List of usage examples for android.app.admin DevicePolicyManager isApplicationHidden
public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName)
From source file:com.example.android.apprestrictionenforcer.StatusFragment.java
private void updateUi(Activity activity) { PackageManager packageManager = activity.getPackageManager(); try {/*from w w w . j a v a 2s . co m*/ ApplicationInfo info = packageManager.getApplicationInfo(Constants.PACKAGE_NAME_APP_RESTRICTION_SCHEMA, PackageManager.GET_UNINSTALLED_PACKAGES); DevicePolicyManager devicePolicyManager = (DevicePolicyManager) activity .getSystemService(Activity.DEVICE_POLICY_SERVICE); if ((info.flags & ApplicationInfo.FLAG_INSTALLED) != 0) { if (!devicePolicyManager.isApplicationHidden(EnforcerDeviceAdminReceiver.getComponentName(activity), Constants.PACKAGE_NAME_APP_RESTRICTION_SCHEMA)) { // The app is ready to enforce restrictions // This is unlikely to happen in this sample as unhideApp() handles it. mListener.onStatusUpdated(); } else { // The app is installed but hidden in this profile mTextStatus.setText(R.string.status_not_activated); mButtonUnhide.setVisibility(View.VISIBLE); } } else { // Need to reinstall the sample app mTextStatus.setText(R.string.status_need_reinstall); mButtonUnhide.setVisibility(View.GONE); } } catch (PackageManager.NameNotFoundException e) { // Need to reinstall the sample app mTextStatus.setText(R.string.status_need_reinstall); mButtonUnhide.setVisibility(View.GONE); } }
From source file:com.example.android.apprestrictionenforcer.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_real); if (null == savedInstanceState) { DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getSystemService( Context.DEVICE_POLICY_SERVICE); PackageManager packageManager = getPackageManager(); if (!devicePolicyManager.isProfileOwnerApp(getApplicationContext().getPackageName())) { // If the managed profile is not yet set up, we show the setup screen. showSetupProfile();/* www .j av a 2s.c o m*/ } else { try { ApplicationInfo info = packageManager.getApplicationInfo( Constants.PACKAGE_NAME_APP_RESTRICTION_SCHEMA, PackageManager.GET_UNINSTALLED_PACKAGES); if (0 == (info.flags & ApplicationInfo.FLAG_INSTALLED)) { // Need to reinstall the sample app showStatusProfile(); } else if (devicePolicyManager.isApplicationHidden( EnforcerDeviceAdminReceiver.getComponentName(this), Constants.PACKAGE_NAME_APP_RESTRICTION_SCHEMA)) { // The app is installed but hidden in this profile showStatusProfile(); } else { // Everything is clear; show the main screen showMainFragment(); } } catch (PackageManager.NameNotFoundException e) { showStatusProfile(); } } } }