android.os.Binder Java Examples
The following examples show how to use
android.os.Binder.
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: MeizuUtils.java From FloatBall with Apache License 2.0 | 6 votes |
@TargetApi(Build.VERSION_CODES.KITKAT) private static boolean checkOp(Context context, int op) { final int version = Build.VERSION.SDK_INT; if (version >= 19) { AppOpsManager manager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); try { Class clazz = AppOpsManager.class; Method method = clazz.getDeclaredMethod("checkOp", int.class, int.class, String.class); return AppOpsManager.MODE_ALLOWED == (int)method.invoke(manager, op, Binder.getCallingUid(), context.getPackageName()); } catch (Exception e) { Log.e(TAG, Log.getStackTraceString(e)); } } else { Log.e(TAG, "Below API 19 cannot invoke!"); } return false; }
Example #2
Source File: IApkManagerImpl.java From letv with Apache License 2.0 | 6 votes |
public List<PackageInfo> getInstalledPackages(int flags) throws RemoteException { waitForReadyInner(); try { enforcePluginFileExists(); List<PackageInfo> infos = new ArrayList(this.mPluginCache.size()); if (shouldNotBlockOtherInfo()) { for (PluginPackageParser pluginPackageParser : this.mPluginCache.values()) { infos.add(pluginPackageParser.getPackageInfo(flags)); } return infos; } List<String> pkgs = this.mActivityManagerService.getPackageNamesByPid(Binder.getCallingPid()); for (PluginPackageParser pluginPackageParser2 : this.mPluginCache.values()) { if (pkgs.contains(pluginPackageParser2.getPackageName())) { infos.add(pluginPackageParser2.getPackageInfo(flags)); } } return infos; } catch (Exception e) { handleException(e); return null; } }
Example #3
Source File: ChromeBrowserProvider.java From delion with Apache License 2.0 | 6 votes |
@SuppressLint("NewApi") private void notifyChange(final Uri uri) { // If the calling user is different than current one, we need to post a // task to notify change, otherwise, a system level hidden permission // INTERACT_ACROSS_USERS_FULL is needed. // The related APIs were added in API 17, it should be safe to fallback to // normal way for notifying change, because caller can't be other users in // devices whose API level is less than API 17. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { UserHandle callingUserHandle = Binder.getCallingUserHandle(); if (callingUserHandle != null && !callingUserHandle.equals(android.os.Process.myUserHandle())) { ThreadUtils.postOnUiThread(new Runnable() { @Override public void run() { getContext().getContentResolver().notifyChange(uri, null); } }); return; } } getContext().getContentResolver().notifyChange(uri, null); }
Example #4
Source File: LockSettingsService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
public String getStringUnchecked(String key, String defaultValue, int userId) { if (Settings.Secure.LOCK_PATTERN_ENABLED.equals(key)) { long ident = Binder.clearCallingIdentity(); try { return mLockPatternUtils.isLockPatternEnabled(userId) ? "1" : "0"; } finally { Binder.restoreCallingIdentity(ident); } } if (userId == USER_FRP) { return getFrpStringUnchecked(key); } if (LockPatternUtils.LEGACY_LOCK_PATTERN_ENABLED.equals(key)) { key = Settings.Secure.LOCK_PATTERN_ENABLED; } return mStorage.readKeyValue(key, defaultValue, userId); }
Example #5
Source File: TvInputManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public void createOverlayView(IBinder sessionToken, IBinder windowToken, Rect frame, int userId) { final int callingUid = Binder.getCallingUid(); final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid, userId, "createOverlayView"); final long identity = Binder.clearCallingIdentity(); try { synchronized (mLock) { try { getSessionLocked(sessionToken, callingUid, resolvedUserId) .createOverlayView(windowToken, frame); } catch (RemoteException | SessionNotFoundException e) { Slog.e(TAG, "error in createOverlayView", e); } } } finally { Binder.restoreCallingIdentity(identity); } }
Example #6
Source File: OverlayManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public boolean setEnabledExclusiveInCategory(@Nullable String packageName, int userId) throws RemoteException { enforceChangeOverlayPackagesPermission("setEnabled"); userId = handleIncomingUser(userId, "setEnabled"); if (packageName == null) { return false; } final long ident = Binder.clearCallingIdentity(); try { synchronized (mLock) { return mImpl.setEnabledExclusive(packageName, true /* withinCategory */, userId); } } finally { Binder.restoreCallingIdentity(ident); } }
Example #7
Source File: Tethering.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private int setWifiTethering(final boolean enable) { int rval = TETHER_ERROR_MASTER_ERROR; final long ident = Binder.clearCallingIdentity(); try { synchronized (mPublicSync) { mWifiTetherRequested = enable; final WifiManager mgr = getWifiManager(); if ((enable && mgr.startSoftAp(null /* use existing wifi config */)) || (!enable && mgr.stopSoftAp())) { rval = TETHER_ERROR_NO_ERROR; } } } finally { Binder.restoreCallingIdentity(ident); } return rval; }
Example #8
Source File: LocationManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Runs some checks for GNSS (FINE) level permissions, used by several methods which directly * (try to) access GNSS information at this layer. */ private boolean hasGnssPermissions(String packageName) { int allowedResolutionLevel = getCallerAllowedResolutionLevel(); checkResolutionLevelIsSufficientForProviderUse( allowedResolutionLevel, LocationManager.GPS_PROVIDER); int pid = Binder.getCallingPid(); int uid = Binder.getCallingUid(); long identity = Binder.clearCallingIdentity(); boolean hasLocationAccess; try { hasLocationAccess = checkLocationAccess(pid, uid, packageName, allowedResolutionLevel); } finally { Binder.restoreCallingIdentity(identity); } return hasLocationAccess; }
Example #9
Source File: QikuUtils.java From SoloPi with Apache License 2.0 | 6 votes |
@TargetApi(Build.VERSION_CODES.KITKAT) private static boolean checkOp(Context context, int op) { final int version = Build.VERSION.SDK_INT; if (version >= 19) { AppOpsManager manager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); try { Class clazz = AppOpsManager.class; Method method = clazz.getDeclaredMethod("checkOp", int.class, int.class, String.class); return AppOpsManager.MODE_ALLOWED == (int)method.invoke(manager, op, Binder.getCallingUid(), context.getPackageName()); } catch (Exception e) { Log.e(TAG, Log.getStackTraceString(e)); } } else { Log.e("", "Below API 19 cannot invoke!"); } return false; }
Example #10
Source File: QikuUtils.java From zone-sdk with MIT License | 6 votes |
@TargetApi(Build.VERSION_CODES.KITKAT) private static boolean checkOp(Context context, int op) { final int version = Build.VERSION.SDK_INT; if (version >= 19) { AppOpsManager manager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); try { Class clazz = AppOpsManager.class; Method method = clazz.getDeclaredMethod("checkOp", int.class, int.class, String.class); return AppOpsManager.MODE_ALLOWED == (int)method.invoke(manager, op, Binder.getCallingUid(), context.getPackageName()); } catch (Exception e) { Log.e(TAG, Log.getStackTraceString(e)); } } else { Log.e("", "Below API 19 cannot invoke!"); } return false; }
Example #11
Source File: NetworkStatsService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Find the most relevant {@link SubscriptionPlan} for the given * {@link NetworkTemplate} and flags. This is typically used to augment * local measurement results to match a known anchor from the carrier. */ private SubscriptionPlan resolveSubscriptionPlan(NetworkTemplate template, int flags) { SubscriptionPlan plan = null; if ((flags & NetworkStatsManager.FLAG_AUGMENT_WITH_SUBSCRIPTION_PLAN) != 0 && mSettings.getAugmentEnabled()) { if (LOGD) Slog.d(TAG, "Resolving plan for " + template); final long token = Binder.clearCallingIdentity(); try { plan = LocalServices.getService(NetworkPolicyManagerInternal.class) .getSubscriptionPlan(template); } finally { Binder.restoreCallingIdentity(token); } if (LOGD) Slog.d(TAG, "Resolved to plan " + plan); } return plan; }
Example #12
Source File: MeizuUtils.java From SoloPi with Apache License 2.0 | 6 votes |
@TargetApi(Build.VERSION_CODES.KITKAT) private static boolean checkOp(Context context, int op) { final int version = Build.VERSION.SDK_INT; if (version >= 19) { AppOpsManager manager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); try { Class clazz = AppOpsManager.class; Method method = clazz.getDeclaredMethod("checkOp", int.class, int.class, String.class); return AppOpsManager.MODE_ALLOWED == (int)method.invoke(manager, op, Binder.getCallingUid(), context.getPackageName()); } catch (Exception e) { Log.e(TAG, Log.getStackTraceString(e)); } } else { Log.e(TAG, "Below API 19 cannot invoke!"); } return false; }
Example #13
Source File: AppsProvider.java From FireFiles with Apache License 2.0 | 6 votes |
@Override public void deleteDocument(String docId) throws FileNotFoundException { final String packageName = getPackageForDocId(docId); final long token = Binder.clearCallingIdentity(); try { if (docId.startsWith(ROOT_ID_USER_APP)) { PackageManagerUtils.uninstallApp(getContext(), packageName); } else if(docId.startsWith(ROOT_ID_PROCESS)) { activityManager.killBackgroundProcesses(getPackageForDocId(docId)); } notifyDocumentsChanged(docId); } finally { Binder.restoreCallingIdentity(token); } }
Example #14
Source File: ContentService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public Bundle getCache(String packageName, Uri key, int userId) { enforceCrossUserPermission(userId, TAG); mContext.enforceCallingOrSelfPermission(android.Manifest.permission.CACHE_CONTENT, TAG); mContext.getSystemService(AppOpsManager.class).checkPackage(Binder.getCallingUid(), packageName); final String providerPackageName = getProviderPackageName(key); final Pair<String, Uri> fullKey = Pair.create(packageName, key); synchronized (mCache) { final ArrayMap<Pair<String, Uri>, Bundle> cache = findOrCreateCacheLocked(userId, providerPackageName); return cache.get(fullKey); } }
Example #15
Source File: NonMediaDocumentsProvider.java From FireFiles with Apache License 2.0 | 6 votes |
@Override public ParcelFileDescriptor openDocument(String docId, String mode, CancellationSignal signal) throws FileNotFoundException { if (!"r".equals(mode)) { throw new IllegalArgumentException("Media is read-only"); } final Uri target = getUriForDocumentId(docId); // Delegate to real provider final long token = Binder.clearCallingIdentity(); try { return getContext().getContentResolver().openFileDescriptor(target, mode); } finally { Binder.restoreCallingIdentity(token); } }
Example #16
Source File: DisplayManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override // Binder call public ParceledListSlice<AmbientBrightnessDayStats> getAmbientBrightnessStats() { mContext.enforceCallingOrSelfPermission( Manifest.permission.ACCESS_AMBIENT_LIGHT_STATS, "Permission required to to access ambient light stats."); final int callingUid = Binder.getCallingUid(); final int userId = UserHandle.getUserId(callingUid); final long token = Binder.clearCallingIdentity(); try { synchronized (mSyncRoot) { return mDisplayPowerController.getAmbientBrightnessStats(userId); } } finally { Binder.restoreCallingIdentity(token); } }
Example #17
Source File: AppOpsService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public List<AppOpsManager.PackageOps> getOpsForPackage(int uid, String packageName, int[] ops) { mContext.enforcePermission(android.Manifest.permission.GET_APP_OPS_STATS, Binder.getCallingPid(), Binder.getCallingUid(), null); String resolvedPackageName = resolvePackageName(uid, packageName); if (resolvedPackageName == null) { return Collections.emptyList(); } synchronized (this) { Ops pkgOps = getOpsRawLocked(uid, resolvedPackageName, false /* edit */, false /* uidMismatchExpected */); if (pkgOps == null) { return null; } ArrayList<AppOpsManager.OpEntry> resOps = collectOps(pkgOps, ops); if (resOps == null) { return null; } ArrayList<AppOpsManager.PackageOps> res = new ArrayList<AppOpsManager.PackageOps>(); AppOpsManager.PackageOps resPackage = new AppOpsManager.PackageOps( pkgOps.packageName, pkgOps.uidState.uid, resOps); res.add(resPackage); return res; } }
Example #18
Source File: IPluginManagerImpl.java From DroidPlugin with GNU Lesser General Public License v3.0 | 6 votes |
@Override public List<ResolveInfo> queryIntentActivities(Intent intent, String resolvedType, int flags) throws RemoteException { waitForReadyInner(); try { enforcePluginFileExists(); if (shouldNotBlockOtherInfo()) { return IntentMatcher.resolveActivityIntent(mContext, mPluginCache, intent, resolvedType, flags); } else { List<String> pkgs = mActivityManagerService.getPackageNamesByPid(Binder.getCallingPid()); List<ResolveInfo> infos = new ArrayList<ResolveInfo>(); for (String pkg : pkgs) { intent.setPackage(pkg); List<ResolveInfo> list = IntentMatcher.resolveActivityIntent(mContext, mPluginCache, intent, resolvedType, flags); infos.addAll(list); } if (infos != null && infos.size() > 0) { return infos; } } } catch (Exception e) { handleException(e); } return null; }
Example #19
Source File: SettingsProvider.java From Study_Android_Demo with Apache License 2.0 | 6 votes |
private int resolveOwningUserIdForSystemSettingLocked(int userId, String setting) { final int parentId; // Resolves dependency if setting has a dependency and the calling user has a parent if (sSystemCloneFromParentOnDependency.containsKey(setting) && (parentId = getGroupParentLocked(userId)) != userId) { // The setting has a dependency and the profile has a parent String dependency = sSystemCloneFromParentOnDependency.get(setting); // Lookup the dependency setting as ourselves, some callers may not have access to it. final long token = Binder.clearCallingIdentity(); try { Setting settingObj = getSecureSetting(dependency, userId); if (settingObj != null && settingObj.getValue().equals("1")) { return parentId; } } finally { Binder.restoreCallingIdentity(token); } } return resolveOwningUserIdLocked(userId, sSystemCloneToManagedSettings, setting); }
Example #20
Source File: IApkManagerImpl.java From letv with Apache License 2.0 | 6 votes |
public List<ResolveInfo> queryIntentActivities(Intent intent, String resolvedType, int flags) throws RemoteException { waitForReadyInner(); try { enforcePluginFileExists(); if (shouldNotBlockOtherInfo()) { return IntentMatcher.resolveActivityIntent(this.mContext, this.mPluginCache, intent, resolvedType, flags); } List<String> pkgs = this.mActivityManagerService.getPackageNamesByPid(Binder.getCallingPid()); List<ResolveInfo> infos = new ArrayList(); for (String pkg : pkgs) { intent.setPackage(pkg); infos.addAll(IntentMatcher.resolveActivityIntent(this.mContext, this.mPluginCache, intent, resolvedType, flags)); } if (infos != null) { if (infos.size() > 0) { return infos; } } return null; } catch (Exception e) { handleException(e); } }
Example #21
Source File: ContentService.java From AndroidComponentPlugin with Apache License 2.0 | 6 votes |
@Override public void requestSync(Account account, String authority, Bundle extras, String callingPackage) { Bundle.setDefusable(extras, true); ContentResolver.validateSyncExtrasBundle(extras); int userId = UserHandle.getCallingUserId(); final int callingUid = Binder.getCallingUid(); final int callingPid = Binder.getCallingPid(); validateExtras(callingUid, extras); final int syncExemption = getSyncExemptionAndCleanUpExtrasForCaller(callingUid, extras); // This makes it so that future permission checks will be in the context of this // process rather than the caller's process. We will restore this before returning. long identityToken = clearCallingIdentity(); try { SyncManager syncManager = getSyncManager(); if (syncManager != null) { syncManager.scheduleSync(account, userId, callingUid, authority, extras, SyncStorageEngine.AuthorityInfo.UNDEFINED, syncExemption, callingUid, callingPid, callingPackage); } } finally { restoreCallingIdentity(identityToken); } }
Example #22
Source File: ContentService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public void putCache(String packageName, Uri key, Bundle value, int userId) { Bundle.setDefusable(value, true); enforceCrossUserPermission(userId, TAG); mContext.enforceCallingOrSelfPermission(android.Manifest.permission.CACHE_CONTENT, TAG); mContext.getSystemService(AppOpsManager.class).checkPackage(Binder.getCallingUid(), packageName); final String providerPackageName = getProviderPackageName(key); final Pair<String, Uri> fullKey = Pair.create(packageName, key); synchronized (mCache) { final ArrayMap<Pair<String, Uri>, Bundle> cache = findOrCreateCacheLocked(userId, providerPackageName); if (value != null) { cache.put(fullKey, value); } else { cache.remove(fullKey); } } }
Example #23
Source File: MediaDocumentsProvider.java From FireFiles with Apache License 2.0 | 6 votes |
@Override public ParcelFileDescriptor openDocument(String docId, String mode, CancellationSignal signal) throws FileNotFoundException { if (!"r".equals(mode)) { throw new IllegalArgumentException("Media is read-only"); } final Uri target = getUriForDocumentId(docId); // Delegate to real provider final long token = Binder.clearCallingIdentity(); try { return getContext().getContentResolver().openFileDescriptor(target, mode); } finally { Binder.restoreCallingIdentity(token); } }
Example #24
Source File: MediaRouterService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public boolean isPlaybackActive(IMediaRouterClient client) { if (client == null) { throw new IllegalArgumentException("client must not be null"); } final long token = Binder.clearCallingIdentity(); try { ClientRecord clientRecord; synchronized (mLock) { clientRecord = mAllClientRecords.get(client.asBinder()); } if (clientRecord != null) { return mAudioPlayerStateMonitor.isPlaybackActive(clientRecord.mUid); } return false; } finally { Binder.restoreCallingIdentity(token); } }
Example #25
Source File: MeizuUtils.java From zone-sdk with MIT License | 6 votes |
@TargetApi(Build.VERSION_CODES.KITKAT) private static boolean checkOp(Context context, int op) { final int version = Build.VERSION.SDK_INT; if (version >= 19) { AppOpsManager manager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); try { Class clazz = AppOpsManager.class; Method method = clazz.getDeclaredMethod("checkOp", int.class, int.class, String.class); return AppOpsManager.MODE_ALLOWED == (int) method.invoke(manager, op, Binder.getCallingUid(), context.getPackageName()); } catch (Exception e) { Log.e(TAG, Log.getStackTraceString(e)); } } else { Log.e(TAG, "Below API 19 cannot invoke!"); } return false; }
Example #26
Source File: SettingsProvider.java From Study_Android_Demo with Apache License 2.0 | 6 votes |
private DatabaseHelper getOrEstablishDatabase(int callingUser) { if (callingUser >= Process.SYSTEM_UID) { if (USER_CHECK_THROWS) { throw new IllegalArgumentException("Uid rather than user handle: " + callingUser); } else { Slog.wtf(TAG, "establish db for uid rather than user: " + callingUser); } } long oldId = Binder.clearCallingIdentity(); try { DatabaseHelper dbHelper; synchronized (this) { dbHelper = mOpenHelpers.get(callingUser); } if (null == dbHelper) { establishDbTracking(callingUser); synchronized (this) { dbHelper = mOpenHelpers.get(callingUser); } } return dbHelper; } finally { Binder.restoreCallingIdentity(oldId); } }
Example #27
Source File: WearableListenerService.java From android_external_GmsLib with Apache License 2.0 | 6 votes |
private boolean post(Runnable runnable) { int callingUid = Binder.getCallingUid(); if (callingUid != knownGoodUid) { // TODO: Verify Gms is calling String[] packagesForUid = getPackageManager().getPackagesForUid(callingUid); if (packagesForUid != null) { if (Arrays.asList(packagesForUid).contains(GMS_PACKAGE_NAME)) { knownGoodUid = callingUid; } else { throw new SecurityException("Caller is not Services Core"); } } } synchronized (lock) { if (disconnected) { return false; } serviceHandler.post(runnable); return true; } }
Example #28
Source File: MediaDocumentsProvider.java From FireFiles with Apache License 2.0 | 6 votes |
@Override public ParcelFileDescriptor openDocument(String docId, String mode, CancellationSignal signal) throws FileNotFoundException { if (!"r".equals(mode)) { throw new IllegalArgumentException("Media is read-only"); } final Uri target = getUriForDocumentId(docId); // Delegate to real provider final long token = Binder.clearCallingIdentity(); try { return getContext().getContentResolver().openFileDescriptor(target, mode); } finally { Binder.restoreCallingIdentity(token); } }
Example #29
Source File: AppOpsManager.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Like {@link #noteProxyOp(int, String)} but instead * of throwing a {@link SecurityException} it returns {@link #MODE_ERRORED}. * @hide */ public int noteProxyOpNoThrow(int op, String proxiedPackageName) { try { return mService.noteProxyOperation(op, mContext.getOpPackageName(), Binder.getCallingUid(), proxiedPackageName); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } }
Example #30
Source File: Session.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Override public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) { synchronized(mService.mWindowMap) { long ident = Binder.clearCallingIdentity(); try { mService.mRoot.mWallpaperController.setWindowWallpaperPosition( mService.windowForClientLocked(this, window, true), x, y, xStep, yStep); } finally { Binder.restoreCallingIdentity(ident); } } }