Java Code Examples for org.chromium.base.ApiCompatibilityUtils#checkPermission()
The following examples show how to use
org.chromium.base.ApiCompatibilityUtils#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: BeamController.java From AndroidChromium with Apache License 2.0 | 6 votes |
/** * If the device has NFC, construct a BeamCallback and pass it to Android. * * @param activity Activity that is sending out beam messages. * @param provider Provider that returns the URL that should be shared. */ public static void registerForBeam(final Activity activity, final BeamProvider provider) { final NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(activity); if (nfcAdapter == null) return; if (ApiCompatibilityUtils.checkPermission( activity, Manifest.permission.NFC, Process.myPid(), Process.myUid()) == PackageManager.PERMISSION_DENIED) { return; } try { final BeamCallback beamCallback = new BeamCallback(activity, provider); nfcAdapter.setNdefPushMessageCallback(beamCallback, activity); nfcAdapter.setOnNdefPushCompleteCallback(beamCallback, activity); } catch (IllegalStateException e) { Log.w("BeamController", "NFC registration failure. Can't retry, giving up."); } }
Example 2
Source File: GeolocationHeader.java From 365browser with Apache License 2.0 | 6 votes |
@CalledByNative static boolean hasGeolocationPermission() { if (sUseAppPermissionGrantedForTesting) return sAppPermissionGrantedForTesting; int pid = Process.myPid(); int uid = Process.myUid(); if (ApiCompatibilityUtils.checkPermission(ContextUtils.getApplicationContext(), Manifest.permission.ACCESS_COARSE_LOCATION, pid, uid) != PackageManager.PERMISSION_GRANTED) { return false; } // Work around a bug in OnePlus2 devices running Lollipop, where the NETWORK_PROVIDER // incorrectly requires FINE_LOCATION permission (it should only require COARSE_LOCATION // permission). http://crbug.com/580733 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M && ApiCompatibilityUtils.checkPermission(ContextUtils.getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION, pid, uid) != PackageManager.PERMISSION_GRANTED) { return false; } return true; }
Example 3
Source File: BeamController.java From 365browser with Apache License 2.0 | 6 votes |
/** * If the device has NFC, construct a BeamCallback and pass it to Android. * * @param activity Activity that is sending out beam messages. * @param provider Provider that returns the URL that should be shared. */ public static void registerForBeam(final Activity activity, final BeamProvider provider) { final NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(activity); if (nfcAdapter == null) return; if (ApiCompatibilityUtils.checkPermission( activity, Manifest.permission.NFC, Process.myPid(), Process.myUid()) == PackageManager.PERMISSION_DENIED) { return; } try { final BeamCallback beamCallback = new BeamCallback(activity, provider); nfcAdapter.setNdefPushMessageCallback(beamCallback, activity); nfcAdapter.setOnNdefPushCompleteCallback(beamCallback, activity); } catch (IllegalStateException e) { Log.w("BeamController", "NFC registration failure. Can't retry, giving up."); } }
Example 4
Source File: SystemAccountManagerDelegate.java From 365browser with Apache License 2.0 | 5 votes |
protected boolean hasManageAccountsPermission() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { return true; } return ApiCompatibilityUtils.checkPermission(ContextUtils.getApplicationContext(), "android.permission.MANAGE_ACCOUNTS", Process.myPid(), Process.myUid()) == PackageManager.PERMISSION_GRANTED; }
Example 5
Source File: WindowAndroid.java From 365browser with Apache License 2.0 | 5 votes |
/** * Determine whether access to a particular permission is granted. * @param permission The permission whose access is to be checked. * @return Whether access to the permission is granted. */ @CalledByNative public final boolean hasPermission(String permission) { if (mPermissionDelegate != null) return mPermissionDelegate.hasPermission(permission); return ApiCompatibilityUtils.checkPermission( mApplicationContext, permission, Process.myPid(), Process.myUid()) == PackageManager.PERMISSION_GRANTED; }
Example 6
Source File: SiteSettingsCategory.java From 365browser with Apache License 2.0 | 5 votes |
/** * Returns whether a per-app permission is enabled. * @param permission The string of the permission to check. */ private boolean permissionOnInAndroid(String permission, Context context) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return true; return PackageManager.PERMISSION_GRANTED == ApiCompatibilityUtils.checkPermission( context, permission, Process.myPid(), Process.myUid()); }
Example 7
Source File: GSAAccountChangeListener.java From 365browser with Apache License 2.0 | 5 votes |
/** * Returns whether the permission {@link ACCOUNT_UPDATE_BROADCAST_PERMISSION} is granted by the * system. */ static boolean holdsAccountUpdatePermission() { Context context = ContextUtils.getApplicationContext(); int result = ApiCompatibilityUtils.checkPermission( context, ACCOUNT_UPDATE_BROADCAST_PERMISSION, Process.myPid(), Process.myUid()); return result == PackageManager.PERMISSION_GRANTED; }
Example 8
Source File: DevToolsServer.java From 365browser with Apache License 2.0 | 5 votes |
@CalledByNative private static boolean checkDebugPermission(int pid, int uid) { String debugPermissionName = ContextUtils.getApplicationContext().getPackageName() + DEBUG_PERMISSION_SIFFIX; return ApiCompatibilityUtils.checkPermission( ContextUtils.getApplicationContext(), debugPermissionName, pid, uid) == PackageManager.PERMISSION_GRANTED; }
Example 9
Source File: SiteSettingsCategory.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * Returns whether a per-app permission is enabled. * @param permission The string of the permission to check. */ private boolean permissionOnInAndroid(String permission, Context context) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return true; return PackageManager.PERMISSION_GRANTED == ApiCompatibilityUtils.checkPermission( context, permission, Process.myPid(), Process.myUid()); }
Example 10
Source File: VrWindowAndroid.java From 365browser with Apache License 2.0 | 4 votes |
@Override public boolean hasPermission(String permission) { return ApiCompatibilityUtils.checkPermission( mApplicationContext, permission, Process.myPid(), Process.myUid()) == PackageManager.PERMISSION_GRANTED; }
Example 11
Source File: GeolocationTracker.java From 365browser with Apache License 2.0 | 4 votes |
private static boolean hasPermission(Context context, String permission) { return ApiCompatibilityUtils.checkPermission( context, permission, Process.myPid(), Process.myUid()) == PackageManager.PERMISSION_GRANTED; }
Example 12
Source File: Preferences.java From AndroidChromium with Apache License 2.0 | 4 votes |
@SuppressFBWarnings("DM_EXIT") @SuppressLint("InlinedApi") @Override protected void onCreate(Bundle savedInstanceState) { ensureActivityNotExported(); // The browser process must be started here because this Activity may be started explicitly // from Android notifications, when Android is restoring Preferences after Chrome was // killed, or for tests. This should happen before super.onCreate() because it might // recreate a fragment, and a fragment might depend on the native library. try { ChromeBrowserInitializer.getInstance(this).handleSynchronousStartup(); } catch (ProcessInitException e) { Log.e(TAG, "Failed to start browser process.", e); // This can only ever happen, if at all, when the activity is started from an Android // notification (or in tests). As such we don't want to show an error messsage to the // user. The application is completely broken at this point, so close it down // completely (not just the activity). System.exit(-1); return; } super.onCreate(savedInstanceState); mIsNewlyCreated = savedInstanceState == null; String initialFragment = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT); Bundle initialArguments = getIntent().getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // If savedInstanceState is non-null, then the activity is being // recreated and super.onCreate() has already recreated the fragment. if (savedInstanceState == null) { if (initialFragment == null) initialFragment = MainPreferences.class.getName(); Fragment fragment = Fragment.instantiate(this, initialFragment, initialArguments); getFragmentManager().beginTransaction() .replace(android.R.id.content, fragment) .commit(); } if (ApiCompatibilityUtils.checkPermission( this, Manifest.permission.NFC, Process.myPid(), Process.myUid()) == PackageManager.PERMISSION_GRANTED) { // Disable Android Beam on JB and later devices. // In ICS it does nothing - i.e. we will send a Play Store link if NFC is used. NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this); if (nfcAdapter != null) nfcAdapter.setNdefPushMessage(null, this); } Resources res = getResources(); ApiCompatibilityUtils.setTaskDescription(this, res.getString(R.string.app_name), BitmapFactory.decodeResource(res, R.mipmap.app_icon), ApiCompatibilityUtils.getColor(res, R.color.default_primary_color)); }
Example 13
Source File: PlatformNetworksManager.java From 365browser with Apache License 2.0 | 4 votes |
private static boolean hasPermission(Context context, String permission) { return ApiCompatibilityUtils.checkPermission( context, permission, Process.myPid(), Process.myUid()) == PackageManager.PERMISSION_GRANTED; }
Example 14
Source File: LocationUtils.java From 365browser with Apache License 2.0 | 4 votes |
private boolean hasPermission(String name) { Context context = ContextUtils.getApplicationContext(); return ApiCompatibilityUtils.checkPermission( context, name, Process.myPid(), Process.myUid()) == PackageManager.PERMISSION_GRANTED; }
Example 15
Source File: Preferences.java From 365browser with Apache License 2.0 | 4 votes |
@SuppressFBWarnings("DM_EXIT") @SuppressLint("InlinedApi") @Override protected void onCreate(Bundle savedInstanceState) { ensureActivityNotExported(); // The browser process must be started here because this Activity may be started explicitly // from Android notifications, when Android is restoring Preferences after Chrome was // killed, or for tests. This should happen before super.onCreate() because it might // recreate a fragment, and a fragment might depend on the native library. try { ChromeBrowserInitializer.getInstance(this).handleSynchronousStartup(); } catch (ProcessInitException e) { Log.e(TAG, "Failed to start browser process.", e); // This can only ever happen, if at all, when the activity is started from an Android // notification (or in tests). As such we don't want to show an error messsage to the // user. The application is completely broken at this point, so close it down // completely (not just the activity). System.exit(-1); return; } super.onCreate(savedInstanceState); mIsNewlyCreated = savedInstanceState == null; String initialFragment = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT); Bundle initialArguments = getIntent().getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // If savedInstanceState is non-null, then the activity is being // recreated and super.onCreate() has already recreated the fragment. if (savedInstanceState == null) { if (initialFragment == null) initialFragment = MainPreferences.class.getName(); Fragment fragment = Fragment.instantiate(this, initialFragment, initialArguments); getFragmentManager().beginTransaction() .replace(android.R.id.content, fragment) .commit(); } if (ApiCompatibilityUtils.checkPermission( this, Manifest.permission.NFC, Process.myPid(), Process.myUid()) == PackageManager.PERMISSION_GRANTED) { // Disable Android Beam on JB and later devices. // In ICS it does nothing - i.e. we will send a Play Store link if NFC is used. NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this); if (nfcAdapter != null) nfcAdapter.setNdefPushMessage(null, this); } Resources res = getResources(); ApiCompatibilityUtils.setTaskDescription(this, res.getString(R.string.app_name), BitmapFactory.decodeResource(res, R.mipmap.app_icon), ApiCompatibilityUtils.getColor(res, R.color.default_primary_color)); }
Example 16
Source File: BackgroundSyncNetworkObserver.java From 365browser with Apache License 2.0 | 4 votes |
private static boolean canCreateObserver() { return ApiCompatibilityUtils.checkPermission(ContextUtils.getApplicationContext(), Manifest.permission.ACCESS_NETWORK_STATE, Process.myPid(), Process.myUid()) == PackageManager.PERMISSION_GRANTED; }
Example 17
Source File: DevToolsServer.java From AndroidChromium with Apache License 2.0 | 4 votes |
@CalledByNative private static boolean checkDebugPermission(Context context, int pid, int uid) { String debugPermissionName = context.getPackageName() + DEBUG_PERMISSION_SIFFIX; return ApiCompatibilityUtils.checkPermission(context, debugPermissionName, pid, uid) == PackageManager.PERMISSION_GRANTED; }
Example 18
Source File: ActivityWindowAndroid.java From 365browser with Apache License 2.0 | 4 votes |
@Override public boolean hasPermission(String permission) { return ApiCompatibilityUtils.checkPermission( mApplicationContext, permission, Process.myPid(), Process.myUid()) == PackageManager.PERMISSION_GRANTED; }
Example 19
Source File: SystemAccountManagerDelegate.java From 365browser with Apache License 2.0 | 4 votes |
protected boolean hasGetAccountsPermission() { return ApiCompatibilityUtils.checkPermission(ContextUtils.getApplicationContext(), Manifest.permission.GET_ACCOUNTS, Process.myPid(), Process.myUid()) == PackageManager.PERMISSION_GRANTED; }
Example 20
Source File: VrWindowAndroid.java From AndroidChromium with Apache License 2.0 | 4 votes |
@Override public boolean hasPermission(String permission) { return ApiCompatibilityUtils.checkPermission( mApplicationContext, permission, Process.myPid(), Process.myUid()) == PackageManager.PERMISSION_GRANTED; }