本文整理匯總了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;
}