List of usage examples for android.os Binder getCallingUid
public static final native int getCallingUid();
From source file:org.getlantern.firetweet.provider.FiretweetDataProvider.java
private void checkWritePermission(final int id, final String table) { switch (id) { case TABLE_ID_ACCOUNTS: { // Writing to accounts database is not allowed for third-party // applications. if (!mPermissionsManager.checkSignature(Binder.getCallingUid())) throw new SecurityException( "Writing to accounts database is not allowed for third-party applications"); break;//from www.j a v a2 s. co m } case TABLE_ID_DIRECT_MESSAGES: case TABLE_ID_DIRECT_MESSAGES_INBOX: case TABLE_ID_DIRECT_MESSAGES_OUTBOX: case TABLE_ID_DIRECT_MESSAGES_CONVERSATION: case TABLE_ID_DIRECT_MESSAGES_CONVERSATION_SCREEN_NAME: case TABLE_ID_DIRECT_MESSAGES_CONVERSATIONS_ENTRIES: { if (!checkPermission(PERMISSION_DIRECT_MESSAGES)) throw new SecurityException( "Access database " + table + " requires level PERMISSION_LEVEL_DIRECT_MESSAGES"); break; } case TABLE_ID_STATUSES: case TABLE_ID_MENTIONS: case TABLE_ID_TABS: case TABLE_ID_DRAFTS: case TABLE_ID_CACHED_USERS: case TABLE_ID_FILTERED_USERS: case TABLE_ID_FILTERED_KEYWORDS: case TABLE_ID_FILTERED_SOURCES: case TABLE_ID_FILTERED_LINKS: case TABLE_ID_TRENDS_LOCAL: case TABLE_ID_CACHED_STATUSES: case TABLE_ID_CACHED_HASHTAGS: { if (!checkPermission(PERMISSION_WRITE)) throw new SecurityException("Access database " + table + " requires level PERMISSION_LEVEL_WRITE"); break; } } }
From source file:com.android.server.MountService.java
@Override public void mountObb(String rawPath, String canonicalPath, String key, IObbActionListener token, int nonce) { Preconditions.checkNotNull(rawPath, "rawPath cannot be null"); Preconditions.checkNotNull(canonicalPath, "canonicalPath cannot be null"); Preconditions.checkNotNull(token, "token cannot be null"); final int callingUid = Binder.getCallingUid(); final ObbState obbState = new ObbState(rawPath, canonicalPath, callingUid, token, nonce); final ObbAction action = new MountObbAction(obbState, key, callingUid); mObbActionHandler.sendMessage(mObbActionHandler.obtainMessage(OBB_RUN_ACTION, action)); if (DEBUG_OBB) Slog.i(TAG, "Send to OBB handler: " + action.toString()); }
From source file:com.android.server.MountService.java
@Override public void unmountObb(String rawPath, boolean force, IObbActionListener token, int nonce) { Preconditions.checkNotNull(rawPath, "rawPath cannot be null"); final ObbState existingState; synchronized (mObbPathToStateMap) { existingState = mObbPathToStateMap.get(rawPath); }/*w w w.ja va 2 s. c o m*/ if (existingState != null) { // TODO: separate state object from request data final int callingUid = Binder.getCallingUid(); final ObbState newState = new ObbState(rawPath, existingState.canonicalPath, callingUid, token, nonce); final ObbAction action = new UnmountObbAction(newState, force); mObbActionHandler.sendMessage(mObbActionHandler.obtainMessage(OBB_RUN_ACTION, action)); if (DEBUG_OBB) Slog.i(TAG, "Send to OBB handler: " + action.toString()); } else { Slog.w(TAG, "Unknown OBB mount at " + rawPath); } }
From source file:com.android.server.MountService.java
/** * Validate a user-supplied password string with cryptfs */// ww w . ja va2 s . com @Override public int verifyEncryptionPassword(String password) throws RemoteException { // Only the system process is permitted to validate passwords if (Binder.getCallingUid() != android.os.Process.SYSTEM_UID) { throw new SecurityException("no permission to access the crypt keeper"); } mContext.enforceCallingOrSelfPermission(Manifest.permission.CRYPT_KEEPER, "no permission to access the crypt keeper"); if (TextUtils.isEmpty(password)) { throw new IllegalArgumentException("password cannot be empty"); } waitForReady(); if (DEBUG_EVENTS) { Slog.i(TAG, "validating encryption password..."); } final NativeDaemonEvent event; try { event = mConnector.execute("cryptfs", "verifypw", new SensitiveArg(toHex(password))); Slog.i(TAG, "cryptfs verifypw => " + event.getMessage()); return Integer.parseInt(event.getMessage()); } catch (NativeDaemonConnectorException e) { // Encryption failed return e.getCode(); } }
From source file:com.android.server.MountService.java
@Override public int mkdirs(String callingPkg, String appPath) { final int userId = UserHandle.getUserId(Binder.getCallingUid()); final UserEnvironment userEnv = new UserEnvironment(userId); // Validate that reported package name belongs to caller final AppOpsManager appOps = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE); appOps.checkPackage(Binder.getCallingUid(), callingPkg); try {//from w ww . j a v a 2 s . c o m appPath = new File(appPath).getCanonicalPath(); } catch (IOException e) { Slog.e(TAG, "Failed to resolve " + appPath + ": " + e); return -1; } if (!appPath.endsWith("/")) { appPath = appPath + "/"; } // Try translating the app path into a vold path, but require that it // belong to the calling package. String voldPath = maybeTranslatePathForVold(appPath, userEnv.buildExternalStorageAppDataDirs(callingPkg), userEnv.buildExternalStorageAppDataDirsForVold(callingPkg)); if (voldPath != null) { try { mConnector.execute("volume", "mkdirs", voldPath); return 0; } catch (NativeDaemonConnectorException e) { return e.getCode(); } } voldPath = maybeTranslatePathForVold(appPath, userEnv.buildExternalStorageAppObbDirs(callingPkg), userEnv.buildExternalStorageAppObbDirsForVold(callingPkg)); if (voldPath != null) { try { mConnector.execute("volume", "mkdirs", voldPath); return 0; } catch (NativeDaemonConnectorException e) { return e.getCode(); } } voldPath = maybeTranslatePathForVold(appPath, userEnv.buildExternalStorageAppMediaDirs(callingPkg), userEnv.buildExternalStorageAppMediaDirsForVold(callingPkg)); if (voldPath != null) { try { mConnector.execute("volume", "mkdirs", voldPath); return 0; } catch (NativeDaemonConnectorException e) { return e.getCode(); } } throw new SecurityException("Invalid mkdirs path: " + appPath); }
From source file:com.android.server.MountService.java
@Override public StorageVolume[] getVolumeList() { final int callingUserId = UserHandle.getCallingUserId(); final boolean accessAll = (mContext.checkPermission(android.Manifest.permission.ACCESS_ALL_EXTERNAL_STORAGE, Binder.getCallingPid(), Binder.getCallingUid()) == PERMISSION_GRANTED); synchronized (mVolumesLock) { final ArrayList<StorageVolume> filtered = Lists.newArrayList(); for (StorageVolume volume : mVolumes) { final UserHandle owner = volume.getOwner(); final boolean ownerMatch = owner == null || owner.getIdentifier() == callingUserId; if (accessAll || ownerMatch) { if (!accessAll && volume.isEmulated()) { filtered.add(0, volume); } else { filtered.add(volume); }/*w w w. j a v a 2 s. co m*/ } } return filtered.toArray(new StorageVolume[filtered.size()]); } }
From source file:com.inmobi.rendering.RenderView.java
public boolean m1976g(String str) { boolean z = true; PackageManager packageManager = this.f1770d.getPackageManager(); boolean z2 = true; switch (str.hashCode()) { case -1886160473: if (str.equals("playVideo")) { z2 = true;/*from w w w.j av a2s . co m*/ break; } break; case -1647691422: if (str.equals("inlineVideo")) { z2 = true; break; } break; case -587360353: if (str.equals("getGalleryImage")) { z2 = true; break; } break; case -178324674: if (str.equals("calendar")) { z2 = true; break; } break; case 114009: if (str.equals("sms")) { z2 = true; break; } break; case 114715: if (str.equals("tel")) { z2 = false; break; } break; case 451310959: if (str.equals("vibrate")) { z2 = true; break; } break; case 459238621: if (str.equals("storePicture")) { z2 = true; break; } break; case 1247233375: if (str.equals("sendMail")) { z2 = true; break; } break; case 1370921258: if (str.equals("microphone")) { z2 = true; break; } break; case 1509574865: if (str.equals("html5video")) { z2 = true; break; } break; case 1642189884: if (str.equals("saveContent")) { z2 = true; break; } break; case 1895570642: if (str.equals("takeCameraPicture")) { z2 = true; break; } break; case 1921345160: if (str.equals("postToSocial")) { z2 = true; break; } break; } Intent intent; ResolveInfo resolveActivity; switch (z2) { case DurationDV.DURATION_TYPE /*0*/: intent = new Intent("android.intent.action.DIAL"); intent.setData(Uri.parse("tel:123456789")); if (this.f1770d.getPackageManager().resolveActivity(intent, AccessibilityNodeInfoCompat.ACTION_CUT) == null) { return false; } return true; case MainNavigationActivity.REQUEST_CODE /*1*/: case DurationDV.DAYTIMEDURATION_TYPE /*2*/: return true; case ConnectionResult.SERVICE_DISABLED /*3*/: z2 = packageManager.hasSystemFeature("android.hardware.microphone") && packageManager.checkPermission("android.permission.RECORD_AUDIO", packageManager.getNameForUid(Binder.getCallingUid())) == 0; return z2; case ConnectionResult.SIGN_IN_REQUIRED /*4*/: case MetaData.DEFAULT_SMART_REDIRECT_TIMEOUT /*5*/: if (VERSION.SDK_INT >= 11 && !(this.f1786t && m1988p())) { z = false; } Logger.m1744a(InternalLogLevel.INTERNAL, f1748a, "HTML5 video supported:" + z); return z; case ConnectionResult.RESOLUTION_REQUIRED /*6*/: if (this.f1770d.getPackageManager().resolveActivity( new Intent("android.intent.action.SENDTO", Uri.parse("smsto:123456789")), AccessibilityNodeInfoCompat.ACTION_CUT) == null) { return false; } return true; case ConnectionResult.NETWORK_ERROR /*7*/: if (VERSION.SDK_INT >= 19 || packageManager.checkPermission("android.permission.WRITE_EXTERNAL_STORAGE", packageManager.getNameForUid(Binder.getCallingUid())) == 0) { return true; } return false; case ConnectionResult.INTERNAL_ERROR /*8*/: intent = new Intent("android.intent.action.SEND"); intent.setType("plain/text"); if (this.f1770d.getPackageManager().resolveActivity(intent, AccessibilityNodeInfoCompat.ACTION_CUT) == null) { return false; } return true; case ConnectionResult.SERVICE_INVALID /*9*/: intent = new Intent("android.intent.action.VIEW"); intent.setType("vnd.android.cursor.item/event"); ResolveInfo resolveActivity2 = this.f1770d.getPackageManager().resolveActivity(intent, AccessibilityNodeInfoCompat.ACTION_CUT); z2 = packageManager.checkPermission("android.permission.WRITE_CALENDAR", packageManager.getNameForUid(Binder.getCallingUid())) == 0; boolean z3; if (packageManager.checkPermission("android.permission.READ_CALENDAR", packageManager.getNameForUid(Binder.getCallingUid())) == 0) { z3 = true; } else { z3 = false; } if (resolveActivity2 != null && z2 && r3) { return true; } return false; case MetaData.DEFAULT_MAX_ADS /*10*/: resolveActivity = this.f1770d.getPackageManager().resolveActivity( new Intent("android.media.action.IMAGE_CAPTURE"), AccessibilityNodeInfoCompat.ACTION_CUT); z2 = packageManager.checkPermission("android.permission.WRITE_EXTERNAL_STORAGE", packageManager.getNameForUid(Binder.getCallingUid())) == 0; if (resolveActivity == null || !z2) { return false; } return true; case ConnectionResult.LICENSE_CHECK_FAILED /*11*/: resolveActivity = this.f1770d.getPackageManager().resolveActivity( new Intent("android.intent.action.PICK", Media.EXTERNAL_CONTENT_URI), AccessibilityNodeInfoCompat.ACTION_CUT); z2 = packageManager.checkPermission("android.permission.WRITE_EXTERNAL_STORAGE", packageManager.getNameForUid(Binder.getCallingUid())) == 0; if (resolveActivity == null || !z2) { return false; } return true; case Tokens.EXPRTOKEN_NODETYPE_COMMENT /*12*/: if (VERSION.SDK_INT < 9 || packageManager.checkPermission("android.permission.WRITE_EXTERNAL_STORAGE", packageManager.getNameForUid(Binder.getCallingUid())) != 0) { return false; } return true; case ConnectionResult.CANCELED /*13*/: Vibrator vibrator = (Vibrator) this.f1770d.getSystemService("vibrator"); if (!(packageManager.checkPermission("android.permission.VIBRATE", packageManager.getNameForUid(Binder.getCallingUid())) == 0) || vibrator == null || VERSION.SDK_INT < 11 || !m1912a(vibrator)) { return false; } return true; default: return false; } }