android.os.Process Java Examples
The following examples show how to use
android.os.Process.
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: PermissionCheckHelper.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 6 votes |
private static boolean checkOpsPermission(Context context, String permission) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { try { AppOpsManager appOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); String opsName = AppOpsManager.permissionToOp(permission); if (opsName == null) { return true; } int opsMode = appOpsManager.checkOpNoThrow(opsName, Process.myUid(), context.getPackageName()); return opsMode == AppOpsManager.MODE_ALLOWED; } catch (Exception ex) { return true; } } return true; }
Example #2
Source File: ActivityApp.java From XPrivacy with GNU General Public License v3.0 | 6 votes |
public RestrictionAdapter(Context context, int resource, ApplicationInfoEx appInfo, String selectedRestrictionName, String selectedMethodName) { mContext = context; mAppInfo = appInfo; mSelectedRestrictionName = selectedRestrictionName; mSelectedMethodName = selectedMethodName; mListRestriction = new ArrayList<String>(); mHook = new LinkedHashMap<Integer, List<Hook>>(); mVersion = new Version(Util.getSelfVersionName(context)); mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); int userId = Util.getUserId(Process.myUid()); boolean fUsed = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFUsed, false); boolean fPermission = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFPermission, false); for (String rRestrictionName : PrivacyManager.getRestrictions(mContext).values()) { boolean isUsed = (PrivacyManager.getUsage(mAppInfo.getUid(), rRestrictionName, null) > 0); boolean hasPermission = PrivacyManager.hasPermission(mContext, mAppInfo, rRestrictionName, mVersion); if (mSelectedRestrictionName != null || ((fUsed ? isUsed : true) && (fPermission ? isUsed || hasPermission : true))) mListRestriction.add(rRestrictionName); } }
Example #3
Source File: PortSweeper.java From android-vlc-remote with GNU General Public License v3.0 | 6 votes |
public PortSweeper(int port, String file, int threadCount, Callback callback, Looper looper) { mPort = port; mPath = file; mWorkerCount = threadCount; mCallback = callback; mAddressQueue = new ConcurrentLinkedQueue<byte[]>(); mWorkerManager = new MyWorkerManager(); mWorkerCallback = new MyWorkerCallback(); mScanThread = new HandlerThread("Scanner", Process.THREAD_PRIORITY_BACKGROUND); mScanThread.start(); Handler.Callback callbackHandlerCallback = new MyCallbackHandlerCallback(); mCallbackHandler = new Handler(looper, callbackHandlerCallback); Handler.Callback scanHandlerCallback = new MyScanHandlerCallback(); mScanHandler = new Handler(mScanThread.getLooper(), scanHandlerCallback); }
Example #4
Source File: ChromeBrowserInitializer.java From AndroidChromium with Apache License 2.0 | 6 votes |
private ActivityStateListener createActivityStateListener() { return new ActivityStateListener() { @Override public void onActivityStateChange(Activity activity, int newState) { if (newState == ActivityState.CREATED || newState == ActivityState.DESTROYED) { // Android destroys Activities at some point after a locale change, but doesn't // kill the process. This can lead to a bug where Chrome is halfway RTL, where // stale natively-loaded resources are not reloaded (http://crbug.com/552618). if (!mInitialLocale.equals(Locale.getDefault())) { Log.e(TAG, "Killing process because of locale change."); Process.killProcess(Process.myPid()); } DeviceFormFactor.resetValuesIfNeeded(mApplication); } } }; }
Example #5
Source File: AppOpsService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
void enforceManageAppOpsModes(int callingPid, int callingUid, int targetUid) { if (callingPid == Process.myPid()) { return; } final int callingUser = UserHandle.getUserId(callingUid); synchronized (this) { if (mProfileOwners != null && mProfileOwners.get(callingUser, -1) == callingUid) { if (targetUid >= 0 && callingUser == UserHandle.getUserId(targetUid)) { // Profile owners are allowed to change modes but only for apps // within their user. return; } } } mContext.enforcePermission(android.Manifest.permission.MANAGE_APP_OPS_MODES, Binder.getCallingPid(), Binder.getCallingUid(), null); }
Example #6
Source File: IPC.java From springreplugin with Apache License 2.0 | 6 votes |
/** * [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); }
Example #7
Source File: PRNGFixes.java From EasyVPN-Free with GNU General Public License v3.0 | 6 votes |
/** * Generates a device- and invocation-specific seed to be mixed into the * Linux PRNG. */ private static byte[] generateSeed() { try { ByteArrayOutputStream seedBuffer = new ByteArrayOutputStream(); DataOutputStream seedBufferOut = new DataOutputStream(seedBuffer); seedBufferOut.writeLong(System.currentTimeMillis()); seedBufferOut.writeLong(System.nanoTime()); seedBufferOut.writeInt(Process.myPid()); seedBufferOut.writeInt(Process.myUid()); seedBufferOut.write(BUILD_FINGERPRINT_AND_DEVICE_SERIAL); seedBufferOut.close(); return seedBuffer.toByteArray(); } catch (IOException e) { throw new SecurityException("Failed to generate seed", e); } }
Example #8
Source File: Framework.java From ACDD with MIT License | 6 votes |
private static void MergeWirteAheads(File storageLocation) { try { File wal = new File(STORAGE_LOCATION, "wal"); String curProcessName = OpenAtlasUtils.getProcessNameByPID(Process.myPid()); log.debug("restoreProfile in process " + curProcessName); String packageName = RuntimeVariables.androidApplication.getPackageName(); if (curProcessName != null && packageName != null && curProcessName.equals(packageName)) { mergeWalsDir(wal, storageLocation); } } catch (Throwable th) { if (Build.MODEL == null || !Build.MODEL.equals("HTC 802w")) { log.error(th.getMessage(), th.getCause()); return; } } }
Example #9
Source File: PRNGFixes.java From secure-storage-android with Apache License 2.0 | 6 votes |
/** * Generates a device- and invocation-specific seed to be mixed into the * Linux PRNG. */ private static byte[] generateSeed() { try { ByteArrayOutputStream seedBuffer = new ByteArrayOutputStream(); DataOutputStream seedBufferOut = new DataOutputStream(seedBuffer); seedBufferOut.writeLong(System.currentTimeMillis()); seedBufferOut.writeLong(System.nanoTime()); seedBufferOut.writeInt(Process.myPid()); seedBufferOut.writeInt(Process.myUid()); seedBufferOut.write(BUILD_FINGERPRINT_AND_DEVICE_SERIAL); seedBufferOut.close(); return seedBuffer.toByteArray(); } catch (IOException e) { throw new SecurityException("Failed to generate seed", e); } }
Example #10
Source File: PRNGFixes.java From GreenBits with GNU General Public License v3.0 | 6 votes |
/** * Generates a device- and invocation-specific seed to be mixed into the * Linux PRNG. */ private static byte[] generateSeed() { try { final ByteArrayOutputStream seedBuffer = new ByteArrayOutputStream(); final DataOutputStream seedBufferOut = new DataOutputStream(seedBuffer); seedBufferOut.writeLong(System.currentTimeMillis()); seedBufferOut.writeLong(System.nanoTime()); seedBufferOut.writeInt(Process.myPid()); seedBufferOut.writeInt(Process.myUid()); seedBufferOut.write(BUILD_FINGERPRINT_AND_DEVICE_SERIAL); seedBufferOut.close(); return seedBuffer.toByteArray(); } catch (final IOException e) { throw new SecurityException("Failed to generate seed", e); } }
Example #11
Source File: AccessibilityManager.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Get an AccessibilityManager instance (create one if necessary). * * @param context Context in which this manager operates. * * @hide */ public static AccessibilityManager getInstance(Context context) { synchronized (sInstanceSync) { if (sInstance == null) { final int userId; if (Binder.getCallingUid() == Process.SYSTEM_UID || context.checkCallingOrSelfPermission( Manifest.permission.INTERACT_ACROSS_USERS) == PackageManager.PERMISSION_GRANTED || context.checkCallingOrSelfPermission( Manifest.permission.INTERACT_ACROSS_USERS_FULL) == PackageManager.PERMISSION_GRANTED) { userId = UserHandle.USER_CURRENT; } else { userId = context.getUserId(); } sInstance = new AccessibilityManager(context, null, userId); } } return sInstance; }
Example #12
Source File: XApplication.java From XPrivacy with GNU General Public License v3.0 | 6 votes |
@Override protected void after(XParam param) throws Throwable { switch (mMethod) { case onCreate: // Install receiver for package management if (PrivacyManager.isApplication(Process.myUid()) && !mReceiverInstalled) try { Application app = (Application) param.thisObject; if (app != null) { mReceiverInstalled = true; Util.log(this, Log.INFO, "Installing receiver uid=" + Process.myUid()); app.registerReceiver(new Receiver(app), new IntentFilter(ACTION_MANAGE_PACKAGE), PERMISSION_MANAGE_PACKAGES, null); } } catch (SecurityException ignored) { } catch (Throwable ex) { Util.bug(this, ex); } break; } }
Example #13
Source File: LoadedApk.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private void setApplicationInfo(ApplicationInfo aInfo) { final int myUid = Process.myUid(); aInfo = adjustNativeLibraryPaths(aInfo); mApplicationInfo = aInfo; mAppDir = aInfo.sourceDir; mResDir = aInfo.uid == myUid ? aInfo.sourceDir : aInfo.publicSourceDir; mOverlayDirs = aInfo.resourceDirs; mDataDir = aInfo.dataDir; mLibDir = aInfo.nativeLibraryDir; mDataDirFile = FileUtils.newFileOrNull(aInfo.dataDir); mDeviceProtectedDataDirFile = FileUtils.newFileOrNull(aInfo.deviceProtectedDataDir); mCredentialProtectedDataDirFile = FileUtils.newFileOrNull(aInfo.credentialProtectedDataDir); mSplitNames = aInfo.splitNames; mSplitAppDirs = aInfo.splitSourceDirs; mSplitResDirs = aInfo.uid == myUid ? aInfo.splitSourceDirs : aInfo.splitPublicSourceDirs; mSplitClassLoaderNames = aInfo.splitClassLoaderNames; if (aInfo.requestsIsolatedSplitLoading() && !ArrayUtils.isEmpty(mSplitNames)) { mSplitLoader = new SplitDependencyLoaderImpl(aInfo.splitDependencies); } }
Example #14
Source File: ActivityThread.java From AndroidComponentPlugin with Apache License 2.0 | 6 votes |
final void handleLowMemory() { ArrayList<ComponentCallbacks2> callbacks; synchronized (mPackages) { callbacks = collectComponentCallbacksLocked(true, null); } final int N = callbacks.size(); for (int i=0; i<N; i++) { callbacks.get(i).onLowMemory(); } // Ask SQLite to free up as much memory as it can, mostly from its page caches. if (Process.myUid() != Process.SYSTEM_UID) { int sqliteReleased = SQLiteDatabase.releaseMemory(); EventLog.writeEvent(SQLITE_MEM_RELEASED_EVENT_LOG_TAG, sqliteReleased); } // Ask graphics to free up as much as possible (font/image caches) Canvas.freeCaches(); // Ask text layout engine to free also as much as possible Canvas.freeTextLayoutCaches(); BinderInternal.forceGc("mem"); }
Example #15
Source File: AppUtils.java From HgLauncher with GNU General Public License v3.0 | 6 votes |
/** * Fetch and return shortcuts for a specific app. * * @param launcherApps LauncherApps service from an activity. * @param componentName The component name to flatten to package name. * * @return A list of shortcut. Null if nonexistent. */ @TargetApi(Build.VERSION_CODES.N_MR1) public static List<ShortcutInfo> getShortcuts(LauncherApps launcherApps, String componentName) { // Return nothing if we don't have permission to retrieve shortcuts. if (launcherApps == null || !launcherApps.hasShortcutHostPermission()) { return new ArrayList<>(0); } LauncherApps.ShortcutQuery shortcutQuery = new LauncherApps.ShortcutQuery(); shortcutQuery.setQueryFlags(LauncherApps.ShortcutQuery.FLAG_MATCH_DYNAMIC | LauncherApps.ShortcutQuery.FLAG_MATCH_MANIFEST | LauncherApps.ShortcutQuery.FLAG_MATCH_PINNED); shortcutQuery.setPackage(getPackageName(componentName)); return launcherApps.getShortcuts(shortcutQuery, Process.myUserHandle()); }
Example #16
Source File: WeChatDecorator.java From decorator-wechat with Apache License 2.0 | 5 votes |
@Override protected void onConnected() { if (SDK_INT >= O) { mWeChatTargetingO = isWeChatTargeting26OrAbove(); final List<NotificationChannel> channels = new ArrayList<>(); channels.add(makeChannel(CHANNEL_GROUP_CONVERSATION, R.string.channel_group_message, false)); // WeChat versions targeting O+ have its own channels for message and misc channels.add(migrate(OLD_CHANNEL_MESSAGE, CHANNEL_MESSAGE, R.string.channel_message, false)); channels.add(migrate(OLD_CHANNEL_MISC, CHANNEL_MISC, R.string.channel_misc, true)); createNotificationChannels(WECHAT_PACKAGE, Process.myUserHandle(), channels); } }
Example #17
Source File: CrashHandler.java From CacheEmulatorChecker with Apache License 2.0 | 5 votes |
@Override public void uncaughtException(Thread thread, Throwable ex) { Process.killProcess( Process.myPid()); ActivityManager manager = (ActivityManager) mApplication.getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()) { if (processInfo.pid == Process.myPid()) { if (!mApplication.getPackageName().equals(processInfo.processName)) { Process.killProcess( Process.myPid()); } break; } } }
Example #18
Source File: ContextImpl.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
@Override public int checkSelfPermission(String permission) { if (permission == null) { throw new IllegalArgumentException("permission is null"); } return checkPermission(permission, Process.myPid(), Process.myUid()); }
Example #19
Source File: MusicBrowserService.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
@Override public BrowserRoot onGetRoot(String clientPackageName, int clientUid, Bundle rootHints) { if (clientPackageName == null || Process.SYSTEM_UID != clientUid && Process.myUid() != clientUid && !clientPackageName.equals("com.google.android.mediasimulator") && !clientPackageName.equals("com.google.android.projection.gearhead")) { return null; } return new BrowserRoot(MEDIA_ID_ROOT, null); }
Example #20
Source File: AsyncTask.java From android-DisplayingBitmaps with Apache License 2.0 | 5 votes |
/** * Creates a new asynchronous task. This constructor must be invoked on the UI thread. */ public AsyncTask() { mWorker = new WorkerRunnable<Params, Result>() { public Result call() throws Exception { mTaskInvoked.set(true); Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); //noinspection unchecked return postResult(doInBackground(mParams)); } }; mFuture = new FutureTask<Result>(mWorker) { @Override protected void done() { try { postResultIfNotInvoked(get()); } catch (InterruptedException e) { android.util.Log.w(LOG_TAG, e); } catch (ExecutionException e) { throw new RuntimeException("An error occured while executing doInBackground()", e.getCause()); } catch (CancellationException e) { postResultIfNotInvoked(null); } } }; }
Example #21
Source File: WeatherUpdateService.java From LittleFreshWeather with Apache License 2.0 | 5 votes |
@Override public void onDestroy() { LogUtil.e(TAG, "onDestroy"); LogUtil.e(TAG, "pid=" + Process.myPid()); LogUtil.e(TAG, "uid=" + Process.myUid()); super.onDestroy(); mUseCase.unsubscribe(); mUseCase.clear(); System.exit(0); }
Example #22
Source File: AndroidHack.java From AtlasForAndroid with MIT License | 5 votes |
public boolean handleMessage(Message message) { try { AndroidHack.ensureLoadedApk(); this.val$handler.handleMessage(message); AndroidHack.ensureLoadedApk(); } catch (Throwable th) { Throwable th2 = th; RuntimeException runtimeException; if ((th2 instanceof ClassNotFoundException) || th2.toString().contains("ClassNotFoundException")) { if (message.what != 113) { Object loadedApk = AndroidHack.getLoadedApk(RuntimeVariables.androidApplication, this.val$activityThread, RuntimeVariables.androidApplication.getPackageName()); if (loadedApk == null) { runtimeException = new RuntimeException("loadedapk is null"); } else { ClassLoader classLoader = (ClassLoader) AtlasHacks.LoadedApk_mClassLoader.get(loadedApk); if (classLoader instanceof DelegateClassLoader) { runtimeException = new RuntimeException("From Atlas:classNotFound ---", th2); } else { RuntimeException runtimeException2 = new RuntimeException("wrong classloader in loadedapk---" + classLoader.getClass().getName(), th2); } } } } else if ((th2 instanceof ClassCastException) || th2.toString().contains("ClassCastException")) { Process.killProcess(Process.myPid()); } else { runtimeException = new RuntimeException(th2); } } return true; }
Example #23
Source File: AsyncTask.java From FireFiles with Apache License 2.0 | 5 votes |
/** * Creates a new asynchronous task. This constructor must be invoked on the UI thread. */ public AsyncTask() { mWorker = new WorkerRunnable<Params, Result>() { public Result call() throws Exception { mTaskInvoked.set(true); Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); //noinspection unchecked return postResult(doInBackground(mParams)); } }; mFuture = new FutureTask<Result>(mWorker) { @Override protected void done() { try { postResultIfNotInvoked(get()); } catch (InterruptedException e) { android.util.Log.w(LOG_TAG, e); } catch (ExecutionException e) { throw new RuntimeException("An error occured while executing doInBackground()", e.getCause()); } catch (CancellationException e) { postResultIfNotInvoked(null); } } }; }
Example #24
Source File: Util.java From XPrivacyLua with GNU General Public License v3.0 | 5 votes |
static UserHandle getUserHandle(int userid) { try { // public UserHandle(int h) Constructor ctor = UserHandle.class.getConstructor(int.class); return (UserHandle) ctor.newInstance(userid); } catch (Throwable ex) { Log.e(TAG, Log.getStackTraceString(ex)); return Process.myUserHandle(); } }
Example #25
Source File: AudioVisualizer.java From vinyl-cast with MIT License | 5 votes |
@Override public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_AUDIO); byte[] rawByteBuffer = new byte[audioBufferSize]; short[] monoShortBuffer = new short[audioBufferSize / 4]; while (!Thread.currentThread().isInterrupted()) { try { int bytesRead = audioInputStream.read(rawByteBuffer, 0, rawByteBuffer.length); if (bytesRead > 0) { int rawAudioBufferIndex = 0; int monoArrayIndex = 0; // split audio into left/right channels and then average for mono audio while (rawAudioBufferIndex < bytesRead) { int leftSample = (short) ((rawByteBuffer[rawAudioBufferIndex] & 0xff) | (rawByteBuffer[rawAudioBufferIndex + 1] << 8)); rawAudioBufferIndex = rawAudioBufferIndex + 2; int rightSample = (short) ((rawByteBuffer[rawAudioBufferIndex] & 0xff) | (rawByteBuffer[rawAudioBufferIndex + 1] << 8)); rawAudioBufferIndex = rawAudioBufferIndex + 2; short mono = (short) ((leftSample + rightSample) / 2); monoShortBuffer[monoArrayIndex] = mono; monoArrayIndex++; } stft.feedData(monoShortBuffer, monoArrayIndex); } } catch (Exception e) { Timber.e(e, "Exception reading audio stream input. Exiting."); break; } } }
Example #26
Source File: NetworkServerService.java From FireFiles with Apache License 2.0 | 5 votes |
@Override public void onCreate() { HandlerThread thread = new HandlerThread( "ServiceStartArguments", Process.THREAD_PRIORITY_BACKGROUND); thread.start(); serviceLooper = thread.getLooper(); serviceHandler = createServiceHandler(serviceLooper, this); }
Example #27
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 #28
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 #29
Source File: RenderState.java From litho with Apache License 2.0 | 5 votes |
@Nullable RenderResult<State> runAndGet() { if (mRunningThreadId.compareAndSet(-1, Process.myTid())) { mFutureTask.run(); try { return mFutureTask.get(); } catch (ExecutionException | InterruptedException e) { // This should never happen since we've already completed the task throw new RuntimeException(e); } } return ThreadUtils.getResultInheritingPriority(mFutureTask, mRunningThreadId.get()); }
Example #30
Source File: ActivityShare.java From XPrivacy with GNU General Public License v3.0 | 5 votes |
public static String getBaseURL() { int userId = Util.getUserId(Process.myUid()); if (PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingHttps, true)) return HTTPS_BASE_URL; else return HTTP_BASE_URL; }