android.content.RestrictionsManager Java Examples

The following examples show how to use android.content.RestrictionsManager. 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 Project: enterprise-samples   Author: android   File: AppRestrictionSchemaFragment.java    License: Apache License 2.0 6 votes vote down vote up
private void resolveRestrictions() {
    RestrictionsManager manager =
            (RestrictionsManager) getActivity().getSystemService(Context.RESTRICTIONS_SERVICE);
    Bundle restrictions = manager.getApplicationRestrictions();
    List<RestrictionEntry> entries = manager.getManifestRestrictions(
            getActivity().getApplicationContext().getPackageName());
    for (RestrictionEntry entry : entries) {
        String key = entry.getKey();
        Log.d(TAG, "key: " + key);
        if (key.equals(KEY_CAN_SAY_HELLO)) {
            updateCanSayHello(entry, restrictions);
        } else if (key.equals(KEY_MESSAGE)) {
            updateMessage(entry, restrictions);
        } else if (key.equals(KEY_NUMBER)) {
            updateNumber(entry, restrictions);
        } else if (key.equals(KEY_RANK)) {
            updateRank(entry, restrictions);
        } else if (key.equals(KEY_APPROVALS)) {
            updateApprovals(entry, restrictions);
        } else if (key.equals(KEY_ITEMS)) {
            updateItems(restrictions);
        }
    }
}
 
Example #2
Source Project: FreezeYou   Author: FreezeYou   File: Support.java    License: Apache License 2.0 6 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
static public boolean checkAndRequestIslandPermission(Context context) {
    final String TYPE_DELEGATION = "com.oasisfeng.island.delegation";
    final String DELEGATION_APP_OPS = "-island-delegation-app-ops";
    final String DELEGATION_PACKAGE_ACCESS = "delegation-package-access";

    final RestrictionsManager rm = (RestrictionsManager) context.getSystemService(Context.RESTRICTIONS_SERVICE);
    if (rm != null && rm.hasRestrictionsProvider()) { // Otherwise, current user is not managed by Island or the version of Island is too low.
        final String[] delegations = rm.getApplicationRestrictions().getStringArray(TYPE_DELEGATION);
        if (delegations == null || !Arrays.asList(delegations).contains(DELEGATION_PACKAGE_ACCESS)) {
            final PersistableBundle request = new PersistableBundle();
            request.putString(RestrictionsManager.REQUEST_KEY_DATA, DELEGATION_PACKAGE_ACCESS);
            rm.requestPermission(TYPE_DELEGATION, "cf.playhi.freezeyou.android.app-ops", request);
        } else {
            return true;
        }
    }
    return false;
}
 
Example #3
Source Project: appauth-android-codelab   Author: googlecodelabs   File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void getAppRestrictions(){
  RestrictionsManager restrictionsManager =
          (RestrictionsManager) this
                  .getSystemService(Context.RESTRICTIONS_SERVICE);

  Bundle appRestrictions = restrictionsManager.getApplicationRestrictions();

  // Block user if KEY_RESTRICTIONS_PENDING is true, and save login hint if available
  if(!appRestrictions.isEmpty()){
    if(appRestrictions.getBoolean(UserManager.
            KEY_RESTRICTIONS_PENDING)!=true){
      mLoginHint = appRestrictions.getString(LOGIN_HINT);
    }
    else {
      Toast.makeText(this,R.string.restrictions_pending_block_user,
              Toast.LENGTH_LONG).show();
      finish();
    }
  }
}
 
Example #4
Source Project: commcare-android   Author: dimagi   File: CommCareSetupActivity.java    License: Apache License 2.0 6 votes vote down vote up
public void checkManagedConfiguration() {
    Log.d(TAG, "Checking managed configuration");
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        // Check for managed configuration
        RestrictionsManager restrictionsManager =
                (RestrictionsManager)getSystemService(Context.RESTRICTIONS_SERVICE);
        Bundle appRestrictions = restrictionsManager.getApplicationRestrictions();
        if (appRestrictions != null && appRestrictions.containsKey("profileUrl")) {
            Log.d(TAG, "Found managed configuration install URL "
                    + appRestrictions.getString("profileUrl"));
            incomingRef = appRestrictions.getString("profileUrl");
            lastInstallMode = INSTALL_MODE_MANAGED_CONFIGURATION;
            uiState = UiState.READY_TO_INSTALL;
            uiStateScreenTransition();
            startResourceInstall();
        }
    }
}
 
Example #5
Source Project: commcare-android   Author: dimagi   File: LoginActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void checkManagedConfiguration() {
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        // Check for managed configuration
        RestrictionsManager restrictionsManager =
                (RestrictionsManager)getSystemService(Context.RESTRICTIONS_SERVICE);
        if (restrictionsManager == null) {
            return;
        }
        Bundle appRestrictions = restrictionsManager.getApplicationRestrictions();
        if (appRestrictions != null && appRestrictions.containsKey("username") &&
                appRestrictions.containsKey("password")) {
            uiController.setUsername(appRestrictions.getString("username"));
            uiController.setPasswordOrPin(appRestrictions.getString("password"));
            initiateLoginAttempt(false);
        }
    }
}
 
Example #6
Source Project: android-AppRestrictionSchema   Author: googlearchive   File: AppRestrictionSchemaFragment.java    License: Apache License 2.0 6 votes vote down vote up
private void resolveRestrictions() {
    RestrictionsManager manager =
            (RestrictionsManager) getActivity().getSystemService(Context.RESTRICTIONS_SERVICE);
    Bundle restrictions = manager.getApplicationRestrictions();
    List<RestrictionEntry> entries = manager.getManifestRestrictions(
            getActivity().getApplicationContext().getPackageName());
    for (RestrictionEntry entry : entries) {
        String key = entry.getKey();
        Log.d(TAG, "key: " + key);
        if (key.equals(KEY_CAN_SAY_HELLO)) {
            updateCanSayHello(entry, restrictions);
        } else if (key.equals(KEY_MESSAGE)) {
            updateMessage(entry, restrictions);
        } else if (key.equals(KEY_NUMBER)) {
            updateNumber(entry, restrictions);
        } else if (key.equals(KEY_RANK)) {
            updateRank(entry, restrictions);
        } else if (key.equals(KEY_APPROVALS)) {
            updateApprovals(entry, restrictions);
        } else if (key.equals(KEY_ITEMS)) {
            updateItems(restrictions);
        }
    }
}
 
Example #7
Source Project: android_9.0.0_r45   Author: lulululbj   File: RestrictionsReceiver.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Intercept standard Restrictions Provider broadcasts.  Implementations
 * should not override this method; it is better to implement the
 * convenience callbacks for each action.
 */
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();

    if (RestrictionsManager.ACTION_REQUEST_PERMISSION.equals(action)) {
        String packageName = intent.getStringExtra(RestrictionsManager.EXTRA_PACKAGE_NAME);
        String requestType = intent.getStringExtra(RestrictionsManager.EXTRA_REQUEST_TYPE);
        String requestId = intent.getStringExtra(RestrictionsManager.EXTRA_REQUEST_ID);
        PersistableBundle request = (PersistableBundle)
                intent.getParcelableExtra(RestrictionsManager.EXTRA_REQUEST_BUNDLE);
        onRequestPermission(context, packageName, requestType, requestId, request);
    }
}
 
Example #8
Source Project: enterprise-samples   Author: android   File: AppRestrictionEnforcerFragment.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Loads the restrictions for the AppRestrictionSchema sample.
 *
 * @param activity The activity
 */
private void loadRestrictions(Activity activity) {
    RestrictionsManager manager =
            (RestrictionsManager) activity.getSystemService(Context.RESTRICTIONS_SERVICE);
    List<RestrictionEntry> restrictions =
            manager.getManifestRestrictions(Constants.PACKAGE_NAME_APP_RESTRICTION_SCHEMA);
    SharedPreferences prefs = activity.getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);
    for (RestrictionEntry restriction : restrictions) {
        String key = restriction.getKey();
        if (RESTRICTION_KEY_SAY_HELLO.equals(key)) {
            updateCanSayHello(prefs.getBoolean(RESTRICTION_KEY_SAY_HELLO,
                    restriction.getSelectedState()));
        } else if (RESTRICTION_KEY_MESSAGE.equals(key)) {
            updateMessage(prefs.getString(RESTRICTION_KEY_MESSAGE,
                    restriction.getSelectedString()));
        } else if (RESTRICTION_KEY_NUMBER.equals(key)) {
            updateNumber(prefs.getInt(RESTRICTION_KEY_NUMBER,
                    restriction.getIntValue()));
        } else if (RESTRICTION_KEY_RANK.equals(key)) {
            updateRank(activity, restriction.getChoiceValues(),
                    prefs.getString(RESTRICTION_KEY_RANK, restriction.getSelectedString()));
        } else if (RESTRICTION_KEY_APPROVALS.equals(key)) {
            updateApprovals(activity, restriction.getChoiceValues(),
                    TextUtils.split(prefs.getString(RESTRICTION_KEY_APPROVALS,
                                    TextUtils.join(DELIMETER,
                                            restriction.getAllSelectedStrings())),
                            DELIMETER));
        } else if (BUNDLE_SUPPORTED && RESTRICTION_KEY_ITEMS.equals(key)) {
            String itemsString = prefs.getString(RESTRICTION_KEY_ITEMS, "");
            HashMap<String, String> items = new HashMap<>();
            for (String itemString : TextUtils.split(itemsString, DELIMETER)) {
                String[] strings = itemString.split(SEPARATOR, 2);
                items.put(strings[0], strings[1]);
            }
            updateItems(activity, items);
        }
    }
}
 
Example #9
Source Project: android-testdpc   Author: googlesamples   File: ManagedConfigurationsFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRetainInstance(true);
    mDevicePolicyManager = (DevicePolicyManager) getActivity().getSystemService(
            Context.DEVICE_POLICY_SERVICE);
    mRestrictionsManager = (RestrictionsManager) getActivity().getSystemService(
            Context.RESTRICTIONS_SERVICE);
    if (Util.hasDelegation(getActivity(), DevicePolicyManager.DELEGATION_APP_RESTRICTIONS)) {
        mAdminComponent = null;
    } else {
        mAdminComponent = DeviceAdminReceiver.getComponentName(getActivity());
    }
}
 
Example #10
Source Project: android-AppRestrictionEnforcer   Author: googlearchive   File: AppRestrictionEnforcerFragment.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Loads the restrictions for the AppRestrictionSchema sample.
 *
 * @param activity The activity
 */
private void loadRestrictions(Activity activity) {
    RestrictionsManager manager =
            (RestrictionsManager) activity.getSystemService(Context.RESTRICTIONS_SERVICE);
    List<RestrictionEntry> restrictions =
            manager.getManifestRestrictions(Constants.PACKAGE_NAME_APP_RESTRICTION_SCHEMA);
    SharedPreferences prefs = activity.getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);
    for (RestrictionEntry restriction : restrictions) {
        String key = restriction.getKey();
        if (RESTRICTION_KEY_SAY_HELLO.equals(key)) {
            updateCanSayHello(prefs.getBoolean(RESTRICTION_KEY_SAY_HELLO,
                    restriction.getSelectedState()));
        } else if (RESTRICTION_KEY_MESSAGE.equals(key)) {
            updateMessage(prefs.getString(RESTRICTION_KEY_MESSAGE,
                    restriction.getSelectedString()));
        } else if (RESTRICTION_KEY_NUMBER.equals(key)) {
            updateNumber(prefs.getInt(RESTRICTION_KEY_NUMBER,
                    restriction.getIntValue()));
        } else if (RESTRICTION_KEY_RANK.equals(key)) {
            updateRank(activity, restriction.getChoiceValues(),
                    prefs.getString(RESTRICTION_KEY_RANK, restriction.getSelectedString()));
        } else if (RESTRICTION_KEY_APPROVALS.equals(key)) {
            updateApprovals(activity, restriction.getChoiceValues(),
                    TextUtils.split(prefs.getString(RESTRICTION_KEY_APPROVALS,
                                    TextUtils.join(DELIMETER,
                                            restriction.getAllSelectedStrings())),
                            DELIMETER));
        } else if (BUNDLE_SUPPORTED && RESTRICTION_KEY_ITEMS.equals(key)) {
            String itemsString = prefs.getString(RESTRICTION_KEY_ITEMS, "");
            HashMap<String, String> items = new HashMap<>();
            for (String itemString : TextUtils.split(itemsString, DELIMETER)) {
                String[] strings = itemString.split(SEPARATOR, 2);
                items.put(strings[0], strings[1]);
            }
            updateItems(activity, items);
        }
    }
}
 
Example #11
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContextImpl.java    License: Apache License 2.0 4 votes vote down vote up
public Object createService(ContextImpl ctx) {
    IBinder b = ServiceManager.getService(RESTRICTIONS_SERVICE);
    IRestrictionsManager service = IRestrictionsManager.Stub.asInterface(b);
    return new RestrictionsManager(ctx, service);
}
 
Example #12
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContextImpl.java    License: Apache License 2.0 4 votes vote down vote up
public Object createService(ContextImpl ctx) {
    IBinder b = ServiceManager.getService(RESTRICTIONS_SERVICE);
    IRestrictionsManager service = IRestrictionsManager.Stub.asInterface(b);
    return new RestrictionsManager(ctx, service);
}
 
Example #13
Source Project: android_9.0.0_r45   Author: lulululbj   File: SystemServiceRegistry.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public RestrictionsManager createService(ContextImpl ctx) throws ServiceNotFoundException {
    IBinder b = ServiceManager.getServiceOrThrow(Context.RESTRICTIONS_SERVICE);
    IRestrictionsManager service = IRestrictionsManager.Stub.asInterface(b);
    return new RestrictionsManager(ctx, service);
}
 
Example #14
Source Project: PowerFileExplorer   Author: PowerExplorer   File: ServiceUtil.java    License: GNU General Public License v3.0 4 votes vote down vote up
@TargetApi(21)
public static RestrictionsManager getRestrictionsManager() {
    return (RestrictionsManager) getSystemService(Context.RESTRICTIONS_SERVICE);
}