本文整理汇总了Java中android.os.Process.myUid方法的典型用法代码示例。如果您正苦于以下问题:Java Process.myUid方法的具体用法?Java Process.myUid怎么用?Java Process.myUid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.os.Process
的用法示例。
在下文中一共展示了Process.myUid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: hasGeolocationPermission
import android.os.Process; //导入方法依赖的package包/类
static boolean hasGeolocationPermission(Context context) {
int pid = Process.myPid();
int uid = Process.myUid();
if (ApiCompatibilityUtils.checkPermission(
context, Manifest.permission.ACCESS_COARSE_LOCATION, pid, uid)
!= PackageManager.PERMISSION_GRANTED) {
return false;
}
// Work around a bug in OnePlus2 devices running Lollipop, where the NETWORK_PROVIDER
// incorrectly requires FINE_LOCATION permission (it should only require COARSE_LOCATION
// permission). http://crbug.com/580733
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M
&& ApiCompatibilityUtils.checkPermission(
context, Manifest.permission.ACCESS_FINE_LOCATION, pid, uid)
!= PackageManager.PERMISSION_GRANTED) {
return false;
}
return true;
}
示例2: openFileUri
import android.os.Process; //导入方法依赖的package包/类
private InputStream openFileUri(Uri uri) throws IOException {
FileInputStream fin = new FileInputStream(uri.getPath());
int owner = FileUtils.getFileDescriptorOwner(fin.getFD());
if (owner == -1 || owner == Process.myUid()) {
fin.close();
throw new IOException("File owned by application");
}
return fin;
}
示例3: afterHookedMethod
import android.os.Process; //导入方法依赖的package包/类
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
if (!param.hasThrowable())
try {
// Do not restrict Zygote
if (Process.myUid() <= 0)
return;
// Pre processing
XParam xparam = XParam.fromXposed(param);
xparam.setExtras(param.getObjectExtra("xextra"));
long start = System.currentTimeMillis();
// Execute hook
mHook.after(xparam);
long ms = System.currentTimeMillis() - start;
if (ms > PrivacyManager.cWarnHookDelayMs)
Util.log(mHook, Log.WARN, String.format("%s %d ms", param.method.getName(), ms));
// Post processing
if (xparam.hasResult())
param.setResult(xparam.getResult());
if (xparam.hasThrowable())
param.setThrowable(xparam.getThrowable());
} catch (Throwable ex) {
Util.bug(null, ex);
}
}
示例4: beforeHookedMethod
import android.os.Process; //导入方法依赖的package包/类
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
try {
// Do not restrict Zygote
if (Process.myUid() <= 0)
return;
// Pre processing
XParam xparam = XParam.fromXposed(param);
long start = System.currentTimeMillis();
// Execute hook
mHook.before(xparam);
long ms = System.currentTimeMillis() - start;
if (ms > PrivacyManager.cWarnHookDelayMs)
Util.log(mHook, Log.WARN, String.format("%s %d ms", param.method.getName(), ms));
// Post processing
if (xparam.hasResult())
param.setResult(xparam.getResult());
if (xparam.hasThrowable())
param.setThrowable(xparam.getThrowable());
param.setObjectExtra("xextra", xparam.getExtras());
} catch (Throwable ex) {
Util.bug(null, ex);
}
}
示例5: start
import android.os.Process; //导入方法依赖的package包/类
@Override
public int start() {
uid = Process.myUid();
if ((trafficRxStart = TrafficStats.getUidRxBytes(uid)) == TrafficStats.UNSUPPORTED) {
return SERVICE_NOT_SUPPORTED;
}
running = true;
trafficTxStart = TrafficStats.getUidTxBytes(uid);
return SERVICE_START_OK;
}
示例6: isCallerForegroundOrSelf
import android.os.Process; //导入方法依赖的package包/类
/**
* @return true when inside a Binder transaction and the caller is in the
* foreground or self. Don't use outside a Binder transaction.
*/
private boolean isCallerForegroundOrSelf() {
int uid = Binder.getCallingUid();
if (uid == Process.myUid()) return true;
// Starting with L MR1, AM.getRunningAppProcesses doesn't return all the
// processes. We use a workaround in this case.
boolean useWorkaround = true;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
do {
ActivityManager am =
(ActivityManager) mApplication.getSystemService(Context.ACTIVITY_SERVICE);
// Extra paranoia here and below, some L 5.0.x devices seem to throw NPE somewhere
// in this code.
// See https://crbug.com/654705.
if (am == null) break;
List<ActivityManager.RunningAppProcessInfo> running = am.getRunningAppProcesses();
if (running == null) break;
for (ActivityManager.RunningAppProcessInfo rpi : running) {
if (rpi == null) continue;
boolean matchingUid = rpi.uid == uid;
boolean isForeground = rpi.importance
== ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
useWorkaround &= !matchingUid;
if (matchingUid && isForeground) return true;
}
} while (false);
}
return useWorkaround ? !isBackgroundProcess(Binder.getCallingPid()) : false;
}
示例7: getUidByPid
import android.os.Process; //导入方法依赖的package包/类
@Override
public int getUidByPid(int pid) {
synchronized (mPidsSelfLocked) {
ProcessRecord r = findProcessLocked(pid);
if (r != null) {
return r.vuid;
}
}
return Process.myUid();
}
示例8: beforeCall
import android.os.Process; //导入方法依赖的package包/类
@Override
public boolean beforeCall(Object who, Method method, Object... args) {
int index = ArrayUtils.indexOfLast(args, Integer.class);
if (index != -1) {
int uid = (int) args[index];
if (uid == Process.myUid()) {
args[index] = getRealUid();
}
}
return super.beforeCall(who, method, args);
}
示例9: beforeCall
import android.os.Process; //导入方法依赖的package包/类
@Override
public boolean beforeCall(Object who, Method method, Object... args) {
int uid = (int) args[index];
if (uid == Process.myUid()) {
args[index] = getRealUid();
}
return super.beforeCall(who, method, args);
}
示例10: killAllOtherProcess
import android.os.Process; //导入方法依赖的package包/类
public static void killAllOtherProcess(Context context) {
for (RunningAppProcessInfo ai : ((ActivityManager) context.getSystemService(ModelName
.ACTIVITY)).getRunningAppProcesses()) {
if (ai.uid == Process.myUid() && ai.pid != Process.myPid()) {
Process.killProcess(ai.pid);
}
}
}
示例11: getFakeUid
import android.os.Process; //导入方法依赖的package包/类
protected int getFakeUid() {
return Process.myUid();
}
示例12: getPackageResourcePath
import android.os.Process; //导入方法依赖的package包/类
public String getPackageResourcePath() {
int myUid = Process.myUid();
ApplicationInfo appInfo = this.mPackage.applicationInfo;
return appInfo.uid == myUid ? appInfo.sourceDir : appInfo.publicSourceDir;
}
示例13: isCallerAllowed
import android.os.Process; //导入方法依赖的package包/类
/**
* @return false if the caller is not authorized to get data from this MediaBrowserService
*/
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
public boolean isCallerAllowed(Context context, String callingPackage, int callingUid) {
// Always allow calls from the framework, self app or development environment.
if (Process.SYSTEM_UID == callingUid || Process.myUid() == callingUid) {
return true;
}
if (isPlatformSigned(context, callingPackage)) {
return true;
}
PackageInfo packageInfo = getPackageInfo(context, callingPackage);
if (packageInfo == null) {
return false;
}
if (packageInfo.signatures.length != 1) {
Log.w(TAG, "Caller does not have exactly one signature certificate!");
return false;
}
String signature = Base64.encodeToString(
packageInfo.signatures[0].toByteArray(), Base64.NO_WRAP);
// Test for known signatures:
ArrayList<CallerInfo> validCallers = mValidCertificates.get(signature);
if (validCallers == null) {
Log.v(TAG, "Signature for caller " + callingPackage + " is not valid: \n"
+ signature);
if (mValidCertificates.isEmpty()) {
Log.w(TAG, "The list of valid certificates is empty. Either your file " +
"res/xml/allowed_media_browser_callers.xml is empty or there was an error " +
"while reading it. Check previous log messages.");
}
return false;
}
// Check if the package name is valid for the certificate:
StringBuffer expectedPackages = new StringBuffer();
for (CallerInfo info: validCallers) {
if (callingPackage.equals(info.packageName)) {
Log.v(TAG, "Valid caller: " + info.name + " package=" + info.packageName +
" release=" + info.release);
return true;
}
expectedPackages.append(info.packageName).append(' ');
}
Log.i(TAG, "Caller has a valid certificate, but its package doesn't match any " +
"expected package for the given certificate. Caller's package is " + callingPackage +
". Expected packages as defined in res/xml/allowed_media_browser_callers.xml are (" +
expectedPackages + "). This caller's certificate is: \n" + signature);
return false;
}
示例14: checkPermission
import android.os.Process; //导入方法依赖的package包/类
@Override public int checkPermission(final String permission, final int pid, final int uid) {
return pid == Process.myPid() && uid == Process.myUid() && mCondom.shouldSpoofPermission(permission) ? PERMISSION_GRANTED
: super.checkPermission(permission, pid, uid);
}
示例15: acquireOriginForSession
import android.os.Process; //导入方法依赖的package包/类
/**
* Acquire the origin for the client that owns the given session.
* @param session The session to use for getting client information.
* @param clientUID The UID for the client controlling the session.
* @return The validated origin {@link Uri} for the given session's client.
*/
protected Uri acquireOriginForSession(CustomTabsSessionToken session, int clientUID) {
if (clientUID == Process.myUid()) return Uri.EMPTY;
return null;
}