android.content.RestrictionsManager源码实例Demo

类android.content.RestrictionsManager源码实例Demo

下面列出了android.content.RestrictionsManager 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

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);
        }
    }
}
 
源代码2 项目: FreezeYou   文件: Support.java
@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;
}
 
源代码3 项目: appauth-android-codelab   文件: MainActivity.java
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();
    }
  }
}
 
源代码4 项目: commcare-android   文件: CommCareSetupActivity.java
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();
        }
    }
}
 
源代码5 项目: commcare-android   文件: LoginActivity.java
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);
        }
    }
}
 
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);
        }
    }
}
 
源代码7 项目: android_9.0.0_r45   文件: RestrictionsReceiver.java
/**
 * 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);
    }
}
 
/**
 * 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);
        }
    }
}
 
@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());
    }
}
 
/**
 * 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);
        }
    }
}
 
源代码11 项目: AndroidComponentPlugin   文件: ContextImpl.java
public Object createService(ContextImpl ctx) {
    IBinder b = ServiceManager.getService(RESTRICTIONS_SERVICE);
    IRestrictionsManager service = IRestrictionsManager.Stub.asInterface(b);
    return new RestrictionsManager(ctx, service);
}
 
源代码12 项目: AndroidComponentPlugin   文件: ContextImpl.java
public Object createService(ContextImpl ctx) {
    IBinder b = ServiceManager.getService(RESTRICTIONS_SERVICE);
    IRestrictionsManager service = IRestrictionsManager.Stub.asInterface(b);
    return new RestrictionsManager(ctx, service);
}
 
源代码13 项目: android_9.0.0_r45   文件: SystemServiceRegistry.java
@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);
}
 
源代码14 项目: PowerFileExplorer   文件: ServiceUtil.java
@TargetApi(21)
public static RestrictionsManager getRestrictionsManager() {
    return (RestrictionsManager) getSystemService(Context.RESTRICTIONS_SERVICE);
}