protected void onCreate()

in AppRestrictionEnforcer/Application/src/main/java/com/example/android/apprestrictionenforcer/MainActivity.java [30:69]


    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        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();
            } else {
                try {
                    int packageFlags;
                    if (Build.VERSION.SDK_INT < 24) {
                        //noinspection deprecation
                        packageFlags = PackageManager.GET_UNINSTALLED_PACKAGES;
                    } else {
                        packageFlags = PackageManager.MATCH_UNINSTALLED_PACKAGES;
                    }
                    ApplicationInfo info = packageManager.getApplicationInfo(
                            Constants.PACKAGE_NAME_APP_RESTRICTION_SCHEMA,
                            packageFlags);
                    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();
                }
            }
        }
    }