Java Code Examples for android.os.Process#myPid()
The following examples show how to use
android.os.Process#myPid() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NDCrashUtils.java From jndcrash with Apache License 2.0 | 6 votes |
/** * Checks if a current process is a background crash service process. * * @param context Current context. * @param serviceClass Class of background crash reporting service. * @return Flag whether a current process is a background crash service process. */ public static boolean isCrashServiceProcess(@NonNull Context context, @NonNull Class<? extends NDCrashService> serviceClass) { final ServiceInfo serviceInfo; try { serviceInfo = context.getPackageManager().getServiceInfo(new ComponentName(context, serviceClass), 0); } catch (PackageManager.NameNotFoundException ignored) { return false; } final int pid = Process.myPid(); final ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); if (manager != null) { for (final ActivityManager.RunningAppProcessInfo info : manager.getRunningAppProcesses()) { if (info.pid == pid) { return serviceInfo.processName.equals(info.processName); } } } return false; }
Example 2
Source File: SenderFilter.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
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; }
Example 3
Source File: AppUtil.java From SimpleProject with MIT License | 6 votes |
/** * 获取APP的进程名 * @param context * @return */ public static String getProcessName(Context context) { int pid = Process.myPid(); ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); if (am == null) { return null; } for (ActivityManager.RunningAppProcessInfo process : am.getRunningAppProcesses()) { if (process.pid == pid) { return process.processName; } } return null; }
Example 4
Source File: LauncherProvider.java From LaunchEnr with GNU General Public License v3.0 | 5 votes |
@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; }
Example 5
Source File: ProcessUtils.java From MixPush with Apache License 2.0 | 5 votes |
/** * 获取当前进程名 */ public static String getProcessName(Context context) { int pid = Process.myPid(); String processName = ""; ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningAppProcessInfo process : manager.getRunningAppProcesses()) { if (process.pid == pid) { processName = process.processName; } } return processName; }
Example 6
Source File: AppOpsService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private void verifyIncomingUid(int uid) { if (uid == Binder.getCallingUid()) { return; } if (Binder.getCallingPid() == Process.myPid()) { return; } mContext.enforcePermission(android.Manifest.permission.UPDATE_APP_OPS_STATS, Binder.getCallingPid(), Binder.getCallingUid(), null); }
Example 7
Source File: QPMGetThreadCountExecutor.java From QPM with Apache License 2.0 | 5 votes |
@Override public void exec() throws QPMException { int pid = Process.myPid(); int threadCount = getThreadsCount(pid); // 计算本GT所占用的线程数 int gtThreadCount = getGTConsumeThreadCount(); threadAnalysis.onCollectThreadInfo(threadCount, gtThreadCount); }
Example 8
Source File: CacheUtils.java From CrawlerForReader with Apache License 2.0 | 5 votes |
/** * 获取缓存实例 * <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; }
Example 9
Source File: CompatibilityDemoInit.java From ans-android-sdk with GNU General Public License v3.0 | 5 votes |
private static boolean shouldInit() { ActivityManager am = ((ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE)); List<ActivityManager.RunningAppProcessInfo> processInfos = am.getRunningAppProcesses(); String mainProcessName = mContext.getApplicationInfo().processName; int myPid = Process.myPid(); for (ActivityManager.RunningAppProcessInfo info : processInfos) { if (info.pid == myPid && mainProcessName.equals(info.processName)) { return true; } } return false; }
Example 10
Source File: PushControllerUtils.java From MiPushFramework with GNU General Public License v3.0 | 5 votes |
/** * Check is in main app process * * @param context Context param * @return is in main process */ public static boolean isAppMainProc(Context context) { for (ActivityManager.RunningAppProcessInfo runningAppProcessInfo : ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)) .getRunningAppProcesses()) { if (runningAppProcessInfo.pid == Process.myPid() && runningAppProcessInfo.processName.equals(context.getPackageName())) { return true; } } return false; }
Example 11
Source File: LauncherProvider.java From Trebuchet with GNU General Public License v3.0 | 5 votes |
private void reloadLauncherIfExternal() { if (Utilities.ATLEAST_MARSHMALLOW && Binder.getCallingPid() != Process.myPid()) { LauncherAppState app = LauncherAppState.getInstanceNoCreate(); if (app != null) { app.reloadWorkspace(); } } }
Example 12
Source File: IOHook.java From container with GNU General Public License v3.0 | 5 votes |
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(); }
Example 13
Source File: WebViewUpdateService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * WebViewFactory calls this to block WebView loading until the relro file is created. * Returns the WebView provider for which we create relro files. */ @Override // Binder call public WebViewProviderResponse waitForAndGetProvider() { // The WebViewUpdateService depends on the prepareWebViewInSystemServer call, which // happens later (during the PHASE_ACTIVITY_MANAGER_READY) in SystemServer.java. If // another service there tries to bring up a WebView in the between, the wait below // would deadlock without the check below. if (Binder.getCallingPid() == Process.myPid()) { throw new IllegalStateException("Cannot create a WebView from the SystemServer"); } return WebViewUpdateService.this.mImpl.waitForAndGetProvider(); }
Example 14
Source File: ContextImpl.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
@Override public int checkCallingPermission(String permission) { if (permission == null) { throw new IllegalArgumentException("permission is null"); } int pid = Binder.getCallingPid(); if (pid != Process.myPid()) { return checkPermission(permission, pid, Binder.getCallingUid()); } return PackageManager.PERMISSION_DENIED; }
Example 15
Source File: SafeActivityOptions.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private void setCallingPidForRemoteAnimationAdapter(ActivityOptions options, int callingPid) { final RemoteAnimationAdapter adapter = options.getRemoteAnimationAdapter(); if (adapter == null) { return; } if (callingPid == Process.myPid()) { Slog.wtf(TAG, "Safe activity options constructed after clearing calling id"); return; } adapter.setCallingPid(callingPid); }
Example 16
Source File: ContextImpl.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
@Override public int checkCallingUriPermission(Uri uri, int modeFlags) { int pid = Binder.getCallingPid(); if (pid != Process.myPid()) { return checkUriPermission(uri, pid, Binder.getCallingUid(), modeFlags); } return PackageManager.PERMISSION_DENIED; }
Example 17
Source File: RemoteLockRpc.java From firebase-android-sdk with Apache License 2.0 | 4 votes |
@Override public long getPid() { return Process.myPid(); }
Example 18
Source File: AppOpsMain.java From AppOpsX with MIT License | 4 votes |
private static void stop(){ int pid = Process.myPid(); System.out.println(" STOP: kill myself ---- pid: " + pid); killProcess(pid); }
Example 19
Source File: PermissionChecker.java From android_9.0.0_r45 with Apache License 2.0 | 3 votes |
/** * Checks whether the IPC you are handling has a given permission and whether * the app op that corresponds to this permission is allowed. * * @param context Context for accessing resources. * @param permission The permission to check. * @param packageName The package name making the IPC. If null the * the first package for the calling UID will be used. * @return The permission check result which is either {@link #PERMISSION_GRANTED} * or {@link #PERMISSION_DENIED} or {@link #PERMISSION_DENIED_APP_OP}. */ @PermissionResult public static int checkCallingPermission(@NonNull Context context, @NonNull String permission, @Nullable String packageName) { if (Binder.getCallingPid() == Process.myPid()) { return PERMISSION_DENIED; } return checkPermission(context, permission, Binder.getCallingPid(), Binder.getCallingUid(), packageName); }