本文整理汇总了Java中android.os.Process.myPid方法的典型用法代码示例。如果您正苦于以下问题:Java Process.myPid方法的具体用法?Java Process.myPid怎么用?Java Process.myPid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.os.Process
的用法示例。
在下文中一共展示了Process.myPid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import android.os.Process; //导入方法依赖的package包/类
/**
* [HIDE] 外界请不要调用此方法
*/
public static void init(Context context) {
sCurrentProcess = SysUtils.getCurrentProcessName();
sCurrentPid = Process.myPid();
sPackageName = context.getApplicationInfo().packageName;
// 设置最终的常驻进程名
String cppn = RePlugin.getConfig().getPersistentName();
if (!TextUtils.isEmpty(cppn)) {
if (cppn.startsWith(":")) {
sPersistentProcessName = sPackageName + cppn;
} else {
sPersistentProcessName = cppn;
}
}
sIsUIProcess = sCurrentProcess.equals(sPackageName);
sIsPersistentProcess = sCurrentProcess.equals(sPersistentProcessName);
}
示例2: isPrivilegedApp
import android.os.Process; //导入方法依赖的package包/类
static boolean isPrivilegedApp(int callerUid, int callerPid) {
if (callerUid == Process.SYSTEM_UID || callerUid == 0 ||
callerPid == Process.myPid() || callerPid == 0) {
return true;
}
IPackageManager pm = AppGlobals.getPackageManager();
try {
return (pm.getPrivateFlagsForUid(callerUid) & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED)
!= 0;
} catch (RemoteException ex) {
Slog.e(IntentFirewall.TAG, "Remote exception while retrieving uid flags",
ex);
}
return false;
}
示例3: isMainProcess
import android.os.Process; //导入方法依赖的package包/类
public static boolean isMainProcess(Context c) {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP) {
ActivityManager am = ((ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE));
List<ActivityManager.RunningAppProcessInfo> processInfos = am.getRunningAppProcesses();
if (processInfos == null) {
return true;
}
String mainProcessName = c.getPackageName();
int myPid = Process.myPid();
for (ActivityManager.RunningAppProcessInfo info : processInfos) {
if (info.pid == myPid && mainProcessName.equals(info.processName)) {
return true;
}
}
return false;
} else {
return !isServiceProcess(c);
}
}
示例4: 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;
}
示例5: getCurrentProcessName
import android.os.Process; //导入方法依赖的package包/类
private static String getCurrentProcessName(Context context) {
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
if (activityManager == null) {
return null;
}
for (ActivityManager.RunningAppProcessInfo processInfo : activityManager.getRunningAppProcesses()) {
if (processInfo.pid == Process.myPid()) {
return processInfo.processName;
}
}
return null;
}
示例6: getInstance
import android.os.Process; //导入方法依赖的package包/类
/**
* 获取缓存实例
* <p>在cacheDir目录</p>
*
* @param cacheDir 缓存目录
* @param maxSize 最大缓存尺寸,单位字节
* @param maxCount 最大缓存个数
* @return {@link CacheUtils}
*/
public static CacheUtils getInstance(@NonNull final File cacheDir, final long maxSize, final int maxCount) {
final String cacheKey = cacheDir.getAbsoluteFile() + "_" + Process.myPid();
CacheUtils cache = CACHE_MAP.get(cacheKey);
if (cache == null) {
cache = new CacheUtils(cacheDir, maxSize, maxCount);
CACHE_MAP.put(cacheKey, cache);
}
return cache;
}
示例7: insert
import android.os.Process; //导入方法依赖的package包/类
@Override
public Uri insert(Uri uri, ContentValues initialValues) {
createDbIfNotExists();
SqlArguments args = new SqlArguments(uri);
// In very limited cases, we support system|signature permission apps to modify the db.
if (Binder.getCallingPid() != Process.myPid()) {
if (!initializeExternalAdd(initialValues)) {
return null;
}
}
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
addModifiedTime(initialValues);
final long rowId = dbInsertAndCheck(mOpenHelper, db, args.table, null, initialValues);
if (rowId < 0) return null;
uri = ContentUris.withAppendedId(uri, rowId);
notifyListeners();
if (Utilities.ATLEAST_MARSHMALLOW) {
reloadLauncherIfExternal();
} else {
// Deprecated behavior to support legacy devices which rely on provider callbacks.
LauncherAppState app = LauncherAppState.getInstanceNoCreate();
if (app != null && "true".equals(uri.getQueryParameter("isExternalAdd"))) {
app.reloadWorkspace();
}
String notify = uri.getQueryParameter("notify");
if (notify == null || "true".equals(notify)) {
getContext().getContentResolver().notifyChange(uri, null);
}
}
return uri;
}
示例8: insert
import android.os.Process; //导入方法依赖的package包/类
@Override
public Uri insert(@NonNull Uri uri, ContentValues initialValues) {
createDbIfNotExists();
SqlArguments args = new SqlArguments(uri);
// In very limited cases, we support system|signature permission apps to modify the db.
if (Binder.getCallingPid() != Process.myPid()) {
if (!initializeExternalAdd(initialValues)) {
return null;
}
}
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
addModifiedTime(initialValues);
final long rowId = dbInsertAndCheck(mOpenHelper, db, args.table, null, initialValues);
if (rowId < 0) return null;
uri = ContentUris.withAppendedId(uri, rowId);
notifyListeners();
if (AndroidVersion.isAtLeastMarshmallow) {
reloadLauncherIfExternal();
} else {
// Deprecated behavior to support legacy devices which rely on provider callbacks.
LauncherAppState app = LauncherAppState.getInstanceNoCreate();
if (app != null && "true".equals(uri.getQueryParameter("isExternalAdd"))) {
app.getModel().forceReload();
}
String notify = uri.getQueryParameter("notify");
if (notify == null || "true".equals(notify)) {
getContext().getContentResolver().notifyChange(uri, null);
}
}
return uri;
}
示例9: onGetCallingUid
import android.os.Process; //导入方法依赖的package包/类
public static int onGetCallingUid(int originUid) {
int callingPid = Binder.getCallingPid();
if (callingPid == Process.myPid()) {
return VClientImpl.get().getBaseVUid();
}
if (callingPid == VirtualCore.get().getSystemPid()) {
return Process.SYSTEM_UID;
}
int vuid = VActivityManager.get().getUidByPid(callingPid);
if (vuid != -1) {
return VUserHandle.getAppId(vuid);
}
VLog.d(TAG, "Unknown uid: " + callingPid);
return VClientImpl.get().getBaseVUid();
}
示例10: shouldInit
import android.os.Process; //导入方法依赖的package包/类
private boolean shouldInit() {
ActivityManager am = ((ActivityManager) getSystemService(Context.ACTIVITY_SERVICE));
List<ActivityManager.RunningAppProcessInfo> processInfos = am.getRunningAppProcesses();
String mainProcessName = getPackageName();
int myPid = Process.myPid();
for (ActivityManager.RunningAppProcessInfo info : processInfos) {
if (info.pid == myPid && mainProcessName.equals(info.processName)) {
return true;
}
}
return false;
}
示例11: getProcessName
import android.os.Process; //导入方法依赖的package包/类
private static @Nullable String getProcessName(final Context context) {
final ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
final List<ActivityManager.RunningAppProcessInfo> processes;
try {
processes = am.getRunningAppProcesses();
} catch (final SecurityException e) { return null; } // Isolated process not allowed to call getRunningAppProcesses
final int pid = Process.myPid();
if (processes != null) for (final ActivityManager.RunningAppProcessInfo process : processes)
if (process.pid == pid) return process.processName;
Log.e(TAG, "Error querying the name of current process.");
return null;
}
示例12: getInstance
import android.os.Process; //导入方法依赖的package包/类
/**
* 获取缓存实例
* <p>在cacheDir目录</p>
*
* @param cacheDir 缓存目录
* @param maxSize 最大缓存尺寸,单位字节
* @param maxCount 最大缓存个数
* @return {@link CacheUtils}
*/
public static CacheUtils getInstance(@NonNull final File cacheDir, final long maxSize, final int maxCount) {
final String cacheKey = cacheDir.getAbsoluteFile() + "_" + Process.myPid();
CacheUtils cache = CACHE_MAP.get(cacheKey);
if (cache == null) {
cache = new CacheUtils(cacheDir, maxSize, maxCount);
CACHE_MAP.put(cacheKey, cache);
}
return cache;
}
示例13: getProcessName
import android.os.Process; //导入方法依赖的package包/类
protected String getProcessName() {
List<RunningAppProcessInfo> runningAppProcesses = ((ActivityManager) this.sAppContext
.getSystemService(ModelName.ACTIVITY)).getRunningAppProcesses();
if (runningAppProcesses != null) {
for (RunningAppProcessInfo runningAppProcessInfo : runningAppProcesses) {
if (runningAppProcessInfo.pid == Process.myPid()) {
return runningAppProcessInfo.processName;
}
}
}
return "com.xiaomi";
}
示例14: getCurrentProcessName
import android.os.Process; //导入方法依赖的package包/类
/**
* getCurrentProcessName
*
* @param context
* @return
*/
public static String getCurrentProcessName(Context context) {
int pid = Process.myPid();
ActivityManager mActivityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
Iterator i$ = mActivityManager.getRunningAppProcesses().iterator();
ActivityManager.RunningAppProcessInfo appProcess;
do {
if (!i$.hasNext()) {
return null;
}
appProcess = (ActivityManager.RunningAppProcessInfo) i$.next();
} while (appProcess.pid != pid);
return appProcess.processName;
}
示例15: u
import android.os.Process; //导入方法依赖的package包/类
static String u(Context context) {
try {
int myPid = Process.myPid();
for (RunningAppProcessInfo runningAppProcessInfo : ((ActivityManager) context
.getSystemService(ModelName.ACTIVITY)).getRunningAppProcesses()) {
if (runningAppProcessInfo.pid == myPid) {
return runningAppProcessInfo.processName;
}
}
} catch (Throwable th) {
}
return null;
}