Java Code Examples for android.content.Context#checkPermission()

The following examples show how to use android.content.Context#checkPermission() . 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: PermissionChecker.java    From letv with Apache License 2.0 7 votes vote down vote up
public static int checkPermission(@NonNull Context context, @NonNull String permission, int pid, int uid, String packageName) {
    if (context.checkPermission(permission, pid, uid) == -1) {
        return -1;
    }
    String op = AppOpsManagerCompat.permissionToOp(permission);
    if (op == null) {
        return 0;
    }
    if (packageName == null) {
        String[] packageNames = context.getPackageManager().getPackagesForUid(uid);
        if (packageNames == null || packageNames.length <= 0) {
            return -1;
        }
        packageName = packageNames[0];
    }
    return AppOpsManagerCompat.noteProxyOp(context, op, packageName) != 0 ? -2 : 0;
}
 
Example 2
Source File: SecureSocketHandler.java    From Dream-Catcher with MIT License 6 votes vote down vote up
private static void enforcePermission(Context context, LocalSocket peer)
    throws IOException, PeerAuthorizationException {
  Credentials credentials = peer.getPeerCredentials();

  int uid = credentials.getUid();
  int pid = credentials.getPid();

  if (LogUtil.isLoggable(Log.VERBOSE)) {
    LogUtil.v("Got request from uid=%d, pid=%d", uid, pid);
  }

  String requiredPermission = Manifest.permission.DUMP;
  int checkResult = context.checkPermission(requiredPermission, pid, uid);
  if (checkResult != PackageManager.PERMISSION_GRANTED) {
    throw new PeerAuthorizationException(
        "Peer pid=" + pid + ", uid=" + uid + " does not have " + requiredPermission);
  }
}
 
Example 3
Source File: PermissionUtil.java    From xposed-rimet with Apache License 2.0 5 votes vote down vote up
public static int checkPermission(Context context, String permission) {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            // 请求权限
            return context.checkPermission(permission, Process.myPid(), Process.myUid());
        }
        return PackageManager.PERMISSION_GRANTED;
    }
 
Example 4
Source File: AwSettings.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public AwSettings(Context context,
        boolean isAccessFromFileURLsGrantedByDefault,
        boolean supportsLegacyQuirks) {
   boolean hasInternetPermission = context.checkPermission(
                android.Manifest.permission.INTERNET,
                Process.myPid(),
                Process.myUid()) == PackageManager.PERMISSION_GRANTED;
    synchronized (mAwSettingsLock) {
        mHasInternetPermission = hasInternetPermission;
        mBlockNetworkLoads = !hasInternetPermission;
        mEventHandler = new EventHandler();
        if (isAccessFromFileURLsGrantedByDefault) {
            mAllowUniversalAccessFromFileURLs = true;
            mAllowFileAccessFromFileURLs = true;
        }

        mUserAgent = LazyDefaultUserAgent.sInstance;

        // Best-guess a sensible initial value based on the features supported on the device.
        mSpatialNavigationEnabled = !context.getPackageManager().hasSystemFeature(
                PackageManager.FEATURE_TOUCHSCREEN);

        // Respect the system setting for password echoing.
        mPasswordEchoEnabled = Settings.System.getInt(context.getContentResolver(),
                Settings.System.TEXT_SHOW_PASSWORD, 1) == 1;

        mSupportLegacyQuirks = supportsLegacyQuirks;
    }
    // Defer initializing the native side until a native WebContents instance is set.
}
 
Example 5
Source File: AwSettings.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public AwSettings(Context context,
        boolean isAccessFromFileURLsGrantedByDefault,
        boolean supportsLegacyQuirks) {
   boolean hasInternetPermission = context.checkPermission(
                android.Manifest.permission.INTERNET,
                Process.myPid(),
                Process.myUid()) == PackageManager.PERMISSION_GRANTED;
    synchronized (mAwSettingsLock) {
        mHasInternetPermission = hasInternetPermission;
        mBlockNetworkLoads = !hasInternetPermission;
        mEventHandler = new EventHandler();
        if (isAccessFromFileURLsGrantedByDefault) {
            mAllowUniversalAccessFromFileURLs = true;
            mAllowFileAccessFromFileURLs = true;
        }

        mUserAgent = LazyDefaultUserAgent.sInstance;

        // Best-guess a sensible initial value based on the features supported on the device.
        mSpatialNavigationEnabled = !context.getPackageManager().hasSystemFeature(
                PackageManager.FEATURE_TOUCHSCREEN);

        // Respect the system setting for password echoing.
        mPasswordEchoEnabled = Settings.System.getInt(context.getContentResolver(),
                Settings.System.TEXT_SHOW_PASSWORD, 1) == 1;

        mSupportLegacyQuirks = supportsLegacyQuirks;
    }
    // Defer initializing the native side until a native WebContents instance is set.
}
 
Example 6
Source File: Utils.java    From AsteroidOSSync with GNU General Public License v3.0 5 votes vote down vote up
public static boolean isLocationEnabledForScanning_byRuntimePermissions(final Context context)
{
	if( Utils.isMarshmallow() )
	{
		return
				context.checkPermission(Manifest.permission.ACCESS_COARSE_LOCATION, android.os.Process.myPid(), android.os.Process.myUid())  == PackageManager.PERMISSION_GRANTED ||
				context.checkPermission(Manifest.permission.ACCESS_FINE_LOCATION, android.os.Process.myPid(), android.os.Process.myUid())  == PackageManager.PERMISSION_GRANTED ;
	}
	else
	{
		return true;
	}
}
 
Example 7
Source File: HttpNegotiateAuthenticator.java    From cronet with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Returns whether the current context lacks a given permission. Skips the check on M+ systems
 * if {@code onlyPreM} is {@code true}, and just returns {@code false}.
 */
@VisibleForTesting
boolean lacksPermission(Context context, String permission, boolean onlyPreM) {
    if (onlyPreM && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) return false;

    int permissionResult =
            context.checkPermission(permission, Process.myPid(), Process.myUid());
    return permissionResult != PackageManager.PERMISSION_GRANTED;
}
 
Example 8
Source File: TaskerIntent.java    From Android-nRF-Beacon with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static boolean havePermission(Context c) {
	return c.checkPermission(PERMISSION_RUN_TASKS, Process.myPid(), Process.myUid()) == PackageManager.PERMISSION_GRANTED;
}
 
Example 9
Source File: Permissions.java    From PhoneProfilesPlus with Apache License 2.0 4 votes vote down vote up
static boolean hasPermission(Context context, String permission) {
    return context.checkPermission(permission, Process.myPid(), Process.myUid()) == PackageManager.PERMISSION_GRANTED;
}
 
Example 10
Source File: DevToolsServer.java    From delion with Apache License 2.0 4 votes vote down vote up
@CalledByNative
private static boolean checkDebugPermission(Context context, int pid, int uid) {
    String debugPermissionName = context.getPackageName() + DEBUG_PERMISSION_SIFFIX;
    return context.checkPermission(debugPermissionName, pid, uid)
            == PackageManager.PERMISSION_GRANTED;
}
 
Example 11
Source File: TaskerIntent.java    From Saiy-PS with GNU Affero General Public License v3.0 4 votes vote down vote up
public static boolean havePermission( Context c ) {
    return c.checkPermission( PERMISSION_RUN_TASKS, Process.myPid(), Process.myUid() ) ==
            PackageManager.PERMISSION_GRANTED;
}
 
Example 12
Source File: TaskerIntent.java    From Telephoto with Apache License 2.0 4 votes vote down vote up
public static boolean havePermission( Context c ) {
    return c.checkPermission( PERMISSION_RUN_TASKS, Process.myPid(), Process.myUid() ) ==
            PackageManager.PERMISSION_GRANTED;
}
 
Example 13
Source File: ContextCompat.java    From letv with Apache License 2.0 4 votes vote down vote up
public static int checkSelfPermission(@NonNull Context context, @NonNull String permission) {
    if (permission != null) {
        return context.checkPermission(permission, Process.myPid(), Process.myUid());
    }
    throw new IllegalArgumentException("permission is null");
}
 
Example 14
Source File: TaskerIntent.java    From beaconloc with Apache License 2.0 4 votes vote down vote up
public static boolean havePermission(Context c) {
	return c.checkPermission(PERMISSION_RUN_TASKS, Process.myPid(), Process.myUid()) == PackageManager.PERMISSION_GRANTED;
}
 
Example 15
Source File: TaskerIntent.java    From androidwebserver with GNU General Public License v3.0 4 votes vote down vote up
public static boolean havePermission( Context c ) {
	return c.checkPermission( PERMISSION_RUN_TASKS, Process.myPid(), Process.myUid() ) == 
		PackageManager.PERMISSION_GRANTED;
}
 
Example 16
Source File: Permissions.java    From island with Apache License 2.0 4 votes vote down vote up
public static boolean has(final Context context, final String permission) { //noinspection SimplifiableIfStatement
	if (TEST_NO_DEV_PERMISSIONS && (INTERACT_ACROSS_USERS.equals(permission) || WRITE_SECURE_SETTINGS.equals(permission))) return false;
	return context.checkPermission(permission, Process.myPid(), Process.myUid()) == PackageManager.PERMISSION_GRANTED;
}
 
Example 17
Source File: TelescopeLayout.java    From telescope with Apache License 2.0 4 votes vote down vote up
private static boolean hasVibratePermission(Context context) {
  return context.checkPermission(VIBRATE, Process.myPid(), Process.myUid()) == PERMISSION_GRANTED;
}
 
Example 18
Source File: TaskerIntent.java    From CarBusInterface with MIT License 4 votes vote down vote up
public static boolean havePermission( Context c ) {
    return c.checkPermission( PERMISSION_RUN_TASKS, Process.myPid(), Process.myUid() ) ==
            PackageManager.PERMISSION_GRANTED;
}
 
Example 19
Source File: Permissions.java    From sentry-android with MIT License 4 votes vote down vote up
public static boolean hasPermission(Context context, String permission) {
  Objects.requireNonNull(context, "The application context is required.");

  return context.checkPermission(permission, Process.myPid(), Process.myUid())
      == PackageManager.PERMISSION_GRANTED;
}
 
Example 20
Source File: PermissionHelper.java    From Utils with Apache License 2.0 3 votes vote down vote up
/**
 * Determine whether <em>you</em> have been granted a particular permission.
 *
 * @param permission The name of the permission being checked.
 * @return {@link android.content.pm.PackageManager#PERMISSION_GRANTED} if you have the
 * permission, or {@link android.content.pm.PackageManager#PERMISSION_DENIED} if not.
 * @see android.content.pm.PackageManager#checkPermission(String, String)
 */
public static int checkSelfPermission(Context context, String permission) {
    if (permission == null) {
        throw new IllegalArgumentException("permission is null");
    }
    return context.checkPermission(permission, Process.myPid(), Process.myUid());
}