Example usage for android.content Context USER_SERVICE

List of usage examples for android.content Context USER_SERVICE

Introduction

In this page you can find the example usage for android.content Context USER_SERVICE.

Prototype

String USER_SERVICE

To view the source code for android.content Context USER_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.os.UserManager for managing users on devices that support multiple users.

Usage

From source file:com.android.car.trust.CarBleTrustAgent.java

@Override
public void onCreate() {
    super.onCreate();

    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "Bluetooth trust agent starting up");
    }//w ww  .  ja v a  2s  .c  o m
    IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_REVOKE_TRUST);
    filter.addAction(ACTION_ADD_TOKEN);
    filter.addAction(ACTION_IS_TOKEN_ACTIVE);
    filter.addAction(ACTION_REMOVE_TOKEN);

    mLocalBroadcastManager = LocalBroadcastManager.getInstance(this /* context */);
    mLocalBroadcastManager.registerReceiver(mTrustEventReceiver, filter);

    // If the user is already unlocked, don't bother starting the BLE service.
    UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
    if (!um.isUserUnlocked()) {
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "User locked, will now bind CarUnlockService");
        }
        Intent intent = new Intent(this, CarUnlockService.class);

        bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE);
    } else {
        setManagingTrust(true);
    }
}

From source file:org.wso2.iot.system.service.SystemService.java

@Override
protected void onHandleIntent(Intent intent) {
    context = this.getApplicationContext();
    cdmDeviceAdmin = new ComponentName(this, ServiceDeviceAdminReceiver.class);
    devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    mUserManager = (UserManager) getSystemService(Context.USER_SERVICE);
    String AGENT_PACKAGE_NAME = context.getPackageName();
    AUTHORIZED_PINNING_APPS = new String[] { AGENT_PACKAGE_NAME, Constants.AGENT_APP_PACKAGE_NAME };
    if (!devicePolicyManager.isAdminActive(cdmDeviceAdmin)) {
        startAdmin();//from w w  w .  j  a v  a 2  s  .c o  m
    } else {
        /*This function handles the "Execute Command on Device" Operation.
        All requests are handled on a single worker thread. They may take as long as necessary
        (and will not block the application's main thread),
        but only one request will be processed at a time.*/
        Log.d(TAG, "Entered onHandleIntent of the Command Runner Service.");
        Bundle extras = intent.getExtras();
        if (extras != null) {
            operationCode = extras.getString("operation");

            if (extras.containsKey("command")) {
                command = extras.getString("command");
                if (command != null) {
                    restrictionCode = command.equals("true");
                }
            }

            if (extras.containsKey("appUri")) {
                appUri = extras.getString("appUri");
            }

            if (extras.containsKey("operationId")) {
                operationId = extras.getInt("operationId");
            }
        }

        if ((operationCode != null)) {
            if (Constants.AGENT_APP_PACKAGE_NAME.equals(intent.getPackage())) {
                Log.d(TAG, "IoT agent has sent a command with operation code: " + operationCode + " command: "
                        + command);
                doTask(operationCode);
            } else {
                Log.d(TAG, "Received command from external application. operation code: " + operationCode
                        + " command: " + command);
                boolean isAutomaticRetry;
                switch (operationCode) {
                case Constants.Operation.FIRMWARE_UPGRADE_AUTOMATIC_RETRY:
                    if ("false".equals(command) || "true".equals(command)) {
                        isAutomaticRetry = "true".equals(command);
                        Preference.putBoolean(context,
                                context.getResources().getString(R.string.firmware_upgrade_automatic_retry),
                                isAutomaticRetry);
                        if (isAutomaticRetry) {
                            String status = Preference.getString(context,
                                    context.getResources().getString(R.string.upgrade_download_status));
                            if (Constants.Status.WIFI_OFF.equals(status) && !checkNetworkOnline()) {
                                Preference.putString(context,
                                        context.getResources().getString(R.string.upgrade_download_status),
                                        Constants.Status.FAILED);
                            } else if (Constants.Status.BATTERY_LEVEL_INSUFFICIENT_TO_DOWNLOAD.equals(status)) {
                                Preference.putString(context,
                                        context.getResources().getString(R.string.upgrade_download_status),
                                        Constants.Status.FAILED);
                            } else if (Constants.Status.BATTERY_LEVEL_INSUFFICIENT_TO_INSTALL
                                    .equals(Preference.getString(context, context.getResources()
                                            .getString(R.string.upgrade_install_status)))) {
                                Preference.putString(context,
                                        context.getResources().getString(R.string.upgrade_install_status),
                                        Constants.Status.FAILED);
                            }
                        }
                        CommonUtils.callAgentApp(context, Constants.Operation.FIRMWARE_UPGRADE_AUTOMATIC_RETRY,
                                0, command); //Sending command as the message
                        CommonUtils.sendBroadcast(context, Constants.Operation.FIRMWARE_UPGRADE_AUTOMATIC_RETRY,
                                Constants.Code.SUCCESS, Constants.Status.SUCCESSFUL, "Updated");
                    } else {
                        CommonUtils.sendBroadcast(context, Constants.Operation.FIRMWARE_UPGRADE_AUTOMATIC_RETRY,
                                Constants.Code.FAILURE, Constants.Status.MALFORMED_REQUEST,
                                "Invalid command argument.");
                    }
                    break;
                case Constants.Operation.UPGRADE_FIRMWARE:
                    try {
                        JSONObject upgradeData = new JSONObject(command);
                        isAutomaticRetry = !Preference.hasPreferenceKey(context,
                                context.getResources().getString(R.string.firmware_upgrade_automatic_retry))
                                || Preference.getBoolean(context, context.getResources()
                                        .getString(R.string.firmware_upgrade_automatic_retry));
                        if (!upgradeData.isNull(
                                context.getResources().getString(R.string.firmware_upgrade_automatic_retry))) {
                            isAutomaticRetry = upgradeData.getBoolean(context.getResources()
                                    .getString(R.string.firmware_upgrade_automatic_retry));
                        }
                        CommonUtils.callAgentApp(context, Constants.Operation.FIRMWARE_UPGRADE_AUTOMATIC_RETRY,
                                0, (isAutomaticRetry ? "true" : "false"));
                    } catch (JSONException e) {
                        String error = "Failed to build JSON object form the request: " + command;
                        Log.e(TAG, error);
                        Preference.putString(context,
                                context.getResources().getString(R.string.upgrade_download_status),
                                Constants.Status.MALFORMED_REQUEST);
                        CommonUtils.sendBroadcast(context, Constants.Operation.UPGRADE_FIRMWARE,
                                Constants.Code.FAILURE, Constants.Status.MALFORMED_REQUEST, error);
                        break;
                    }
                case Constants.Operation.GET_FIRMWARE_UPGRADE_PACKAGE_STATUS:
                case Constants.Operation.GET_FIRMWARE_BUILD_DATE:
                case Constants.Operation.GET_FIRMWARE_UPGRADE_DOWNLOAD_PROGRESS:
                    doTask(operationCode);
                    break;
                default:
                    Log.e(TAG, "Invalid operation code: " + operationCode);
                    break;
                }
            }
        }
    }
    context.registerReceiver(new BatteryChargingStateReceiver(),
            new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

    //Checking is there any interrupted firmware download is there
    String status = Preference.getString(context,
            context.getResources().getString(R.string.upgrade_download_status));
    if (Constants.Status.OTA_UPGRADE_ONGOING.equals(status)) {
        Preference.putString(context, context.getResources().getString(R.string.upgrade_download_status),
                Constants.Status.REQUEST_PLACED);
        Timer timeoutTimer = new Timer();
        timeoutTimer.schedule(new TimerTask() {
            @Override
            public void run() {
                if (Constants.Status.REQUEST_PLACED.equals(Preference.getString(context,
                        context.getResources().getString(R.string.upgrade_download_status)))) {
                    if (Preference.getBoolean(context,
                            context.getResources().getString(R.string.firmware_upgrade_automatic_retry))) {
                        Log.i(TAG,
                                "Found incomplete firmware download. Proceeding with last download request from the agent.");
                        OTADownload otaDownload = new OTADownload(context);
                        otaDownload.startOTA();
                    }
                }
            }
        }, Constants.FIRMWARE_UPGRADE_READ_TIMEOUT);
    }
}

From source file:org.wso2.emm.system.service.EMMSystemService.java

@Override
protected void onHandleIntent(Intent intent) {
    context = this.getApplicationContext();
    cdmDeviceAdmin = new ComponentName(this, ServiceDeviceAdminReceiver.class);
    devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    mUserManager = (UserManager) getSystemService(Context.USER_SERVICE);
    AGENT_PACKAGE_NAME = context.getPackageName();
    AUTHORIZED_PINNING_APPS = new String[] { AGENT_PACKAGE_NAME, Constants.AGENT_APP_PACKAGE_NAME };
    if (!devicePolicyManager.isAdminActive(cdmDeviceAdmin)) {
        startAdmin();//  w  w w.j  a v a 2s. c  o  m
    } else {
        /*This function handles the "Execute Command on Device" Operation.
        All requests are handled on a single worker thread. They may take as long as necessary
        (and will not block the application's main thread),
        but only one request will be processed at a time.*/
        Log.d(TAG, "Entered onHandleIntent of the Command Runner Service.");
        Bundle extras = intent.getExtras();
        if (extras != null) {
            operationCode = extras.getString("operation");

            if (extras.containsKey("command")) {
                command = extras.getString("command");
                if (command != null) {
                    restrictionCode = command.equals("true");
                }
            }

            if (extras.containsKey("appUri")) {
                appUri = extras.getString("appUri");
            }

            if (extras.containsKey("operationId")) {
                operationId = extras.getInt("operationId");
            }
        }

        if ((operationCode != null)) {
            if (Constants.AGENT_APP_PACKAGE_NAME.equals(intent.getPackage())) {
                Log.d(TAG, "EMM agent has sent a command with operation code: " + operationCode + " command: "
                        + command);
                doTask(operationCode);
            } else {
                Log.d(TAG, "Received command from external application. operation code: " + operationCode
                        + " command: " + command);
                boolean isAutomaticRetry;
                switch (operationCode) {
                case Constants.Operation.FIRMWARE_UPGRADE_AUTOMATIC_RETRY:
                    if ("false".equals(command) || "true".equals(command)) {
                        isAutomaticRetry = "true".equals(command);
                        Preference.putBoolean(context,
                                context.getResources().getString(R.string.firmware_upgrade_automatic_retry),
                                isAutomaticRetry);
                        if (isAutomaticRetry) {
                            String status = Preference.getString(context,
                                    context.getResources().getString(R.string.upgrade_download_status));
                            if (Constants.Status.WIFI_OFF.equals(status) && !checkNetworkOnline()) {
                                Preference.putString(context,
                                        context.getResources().getString(R.string.upgrade_download_status),
                                        Constants.Status.FAILED);
                            } else if (Constants.Status.BATTERY_LEVEL_INSUFFICIENT_TO_DOWNLOAD.equals(status)) {
                                Preference.putString(context,
                                        context.getResources().getString(R.string.upgrade_download_status),
                                        Constants.Status.FAILED);
                            } else if (Constants.Status.BATTERY_LEVEL_INSUFFICIENT_TO_INSTALL
                                    .equals(Preference.getString(context, context.getResources()
                                            .getString(R.string.upgrade_install_status)))) {
                                Preference.putString(context,
                                        context.getResources().getString(R.string.upgrade_install_status),
                                        Constants.Status.FAILED);
                            }
                        }
                        CommonUtils.callAgentApp(context, Constants.Operation.FIRMWARE_UPGRADE_AUTOMATIC_RETRY,
                                0, command); //Sending command as the message
                        CommonUtils.sendBroadcast(context, Constants.Operation.FIRMWARE_UPGRADE_AUTOMATIC_RETRY,
                                Constants.Code.SUCCESS, Constants.Status.SUCCESSFUL, "Updated");
                    } else {
                        CommonUtils.sendBroadcast(context, Constants.Operation.FIRMWARE_UPGRADE_AUTOMATIC_RETRY,
                                Constants.Code.FAILURE, Constants.Status.MALFORMED_REQUEST,
                                "Invalid command argument.");
                    }
                    break;
                case Constants.Operation.UPGRADE_FIRMWARE:
                    try {
                        JSONObject upgradeData = new JSONObject(command);
                        isAutomaticRetry = (Preference.hasPreferenceKey(context,
                                context.getResources().getString(R.string.firmware_upgrade_automatic_retry))
                                && Preference.getBoolean(context,
                                        context.getResources()
                                                .getString(R.string.firmware_upgrade_automatic_retry)))
                                || !Preference.hasPreferenceKey(context, context.getResources()
                                        .getString(R.string.firmware_upgrade_automatic_retry));
                        if (!upgradeData.isNull(
                                context.getResources().getString(R.string.firmware_upgrade_automatic_retry))) {
                            isAutomaticRetry = upgradeData.getBoolean(context.getResources()
                                    .getString(R.string.firmware_upgrade_automatic_retry));
                        }
                        CommonUtils.callAgentApp(context, Constants.Operation.FIRMWARE_UPGRADE_AUTOMATIC_RETRY,
                                0, (isAutomaticRetry ? "true" : "false"));
                    } catch (JSONException e) {
                        String error = "Failed to build JSON object form the request: " + command;
                        Log.e(TAG, error);
                        Preference.putString(context,
                                context.getResources().getString(R.string.upgrade_download_status),
                                Constants.Status.MALFORMED_REQUEST);
                        CommonUtils.sendBroadcast(context, Constants.Operation.UPGRADE_FIRMWARE,
                                Constants.Code.FAILURE, Constants.Status.MALFORMED_REQUEST, error);
                        break;
                    }
                case Constants.Operation.GET_FIRMWARE_UPGRADE_PACKAGE_STATUS:
                case Constants.Operation.GET_FIRMWARE_BUILD_DATE:
                case Constants.Operation.GET_FIRMWARE_UPGRADE_DOWNLOAD_PROGRESS:
                    doTask(operationCode);
                    break;
                default:
                    Log.e(TAG, "Invalid operation code: " + operationCode);
                    break;
                }
            }
        }
    }
    context.registerReceiver(new BatteryChargingStateReceiver(),
            new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

    //Checking is there any interrupted firmware download is there
    String status = Preference.getString(context,
            context.getResources().getString(R.string.upgrade_download_status));
    if (Constants.Status.OTA_UPGRADE_ONGOING.equals(status)) {
        Preference.putString(context, context.getResources().getString(R.string.upgrade_download_status),
                Constants.Status.REQUEST_PLACED);
        Timer timeoutTimer = new Timer();
        timeoutTimer.schedule(new TimerTask() {
            @Override
            public void run() {
                if (Constants.Status.REQUEST_PLACED.equals(Preference.getString(context,
                        context.getResources().getString(R.string.upgrade_download_status)))) {
                    if (Preference.getBoolean(context,
                            context.getResources().getString(R.string.firmware_upgrade_automatic_retry))) {
                        Log.i(TAG,
                                "Found incomplete firmware download. Proceeding with last download request from the agent.");
                        OTADownload otaDownload = new OTADownload(context);
                        otaDownload.startOTA();
                    }
                }
            }
        }, Constants.FIRMWARE_UPGRADE_READ_TIMEOUT);
    }
}

From source file:com.android.managedprovisioning.ProfileOwnerProvisioningService.java

@Override
public void onCreate() {
    super.onCreate();

    mIpm = IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
    mAccountManager = (AccountManager) getSystemService(Context.ACCOUNT_SERVICE);
    mUserManager = (UserManager) getSystemService(Context.USER_SERVICE);

    runnerTask = new RunnerTask();
}

From source file:com.android.dialer.settings.DialerSettingsActivity.java

/**
 * @return Whether the current user is the primary user.
 *///  ww  w.j  av  a 2s. c  om
private boolean isPrimaryUser() {
    return UserManagerCompat.isSystemUser((UserManager) getSystemService(Context.USER_SERVICE));
}

From source file:com.nick.scalpel.core.AutoFoundWirer.java

private void wireFromContext(Context context, AutoFound.Type type, int idRes, Resources.Theme theme,
        Field field, Object forWho) {
    Resources resources = context.getResources();
    switch (type) {
    case STRING://from ww  w  . j a  v a 2  s. c  o m
        setField(field, forWho, resources.getString(idRes));
        break;
    case COLOR:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            setField(field, forWho, resources.getColor(idRes, theme));
        } else {
            //noinspection deprecation
            setField(field, forWho, resources.getColor(idRes));
        }
        break;
    case INTEGER:
        setField(field, forWho, resources.getInteger(idRes));
        break;
    case BOOL:
        setField(field, forWho, resources.getBoolean(idRes));
        break;
    case STRING_ARRAY:
        setField(field, forWho, resources.getStringArray(idRes));
        break;
    case INT_ARRAY:
        setField(field, forWho, resources.getIntArray(idRes));
        break;
    case PM:
        setField(field, forWho, context.getSystemService(Context.POWER_SERVICE));
        break;
    case ACCOUNT:
        setField(field, forWho, context.getSystemService(Context.ACCOUNT_SERVICE));
        break;
    case ALARM:
        setField(field, forWho, context.getSystemService(Context.ALARM_SERVICE));
        break;
    case AM:
        setField(field, forWho, context.getSystemService(Context.ACTIVITY_SERVICE));
        break;
    case WM:
        setField(field, forWho, context.getSystemService(Context.WINDOW_SERVICE));
        break;
    case NM:
        setField(field, forWho, context.getSystemService(Context.NOTIFICATION_SERVICE));
        break;
    case TM:
        setField(field, forWho, context.getSystemService(Context.TELEPHONY_SERVICE));
        break;
    case TCM:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            setField(field, forWho, context.getSystemService(Context.TELECOM_SERVICE));
        }
        break;
    case SP:
        setField(field, forWho, PreferenceManager.getDefaultSharedPreferences(context));
        break;
    case PKM:
        setField(field, forWho, context.getPackageManager());
        break;
    case HANDLE:
        setField(field, forWho, new Handler(Looper.getMainLooper()));
        break;
    case ASM:
        setField(field, forWho, context.getSystemService(Context.ACCESSIBILITY_SERVICE));
        break;
    case CAP:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            setField(field, forWho, context.getSystemService(Context.CAPTIONING_SERVICE));
        }
        break;
    case KGD:
        setField(field, forWho, context.getSystemService(Context.KEYGUARD_SERVICE));
        break;
    case LOCATION:
        setField(field, forWho, context.getSystemService(Context.LOCATION_SERVICE));
        break;
    case SEARCH:
        setField(field, forWho, context.getSystemService(Context.SEARCH_SERVICE));
        break;
    case SENSOR:
        setField(field, forWho, context.getSystemService(Context.SENSOR_SERVICE));
        break;
    case STORAGE:
        setField(field, forWho, context.getSystemService(Context.STORAGE_SERVICE));
        break;
    case WALLPAPER:
        setField(field, forWho, context.getSystemService(Context.WALLPAPER_SERVICE));
        break;
    case VIBRATOR:
        setField(field, forWho, context.getSystemService(Context.VIBRATOR_SERVICE));
        break;
    case CONNECT:
        setField(field, forWho, context.getSystemService(Context.CONNECTIVITY_SERVICE));
        break;
    case NETWORK_STATUS:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            setField(field, forWho, context.getSystemService(Context.NETWORK_STATS_SERVICE));
        }
        break;
    case WIFI:
        setField(field, forWho, context.getSystemService(Context.WIFI_SERVICE));
        break;
    case AUDIO:
        setField(field, forWho, context.getSystemService(Context.AUDIO_SERVICE));
        break;
    case FP:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            setField(field, forWho, context.getSystemService(Context.FINGERPRINT_SERVICE));
        }
        break;
    case MEDIA_ROUTER:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            setField(field, forWho, context.getSystemService(Context.MEDIA_ROUTER_SERVICE));
        }
        break;
    case SUB:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
            setField(field, forWho, context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE));
        }
        break;
    case IME:
        setField(field, forWho, context.getSystemService(Context.INPUT_METHOD_SERVICE));
        break;
    case CLIP_BOARD:
        setField(field, forWho, context.getSystemService(Context.CLIPBOARD_SERVICE));
        break;
    case APP_WIDGET:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            setField(field, forWho, context.getSystemService(Context.APPWIDGET_SERVICE));
        }
        break;
    case DEVICE_POLICY:
        setField(field, forWho, context.getSystemService(Context.DEVICE_POLICY_SERVICE));
        break;
    case DOWNLOAD:
        setField(field, forWho, context.getSystemService(Context.DOWNLOAD_SERVICE));
        break;
    case BATTERY:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            setField(field, forWho, context.getSystemService(Context.BATTERY_SERVICE));
        }
        break;
    case NFC:
        setField(field, forWho, context.getSystemService(Context.NFC_SERVICE));
        break;
    case DISPLAY:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            setField(field, forWho, context.getSystemService(Context.DISPLAY_SERVICE));
        }
        break;
    case USER:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            setField(field, forWho, context.getSystemService(Context.USER_SERVICE));
        }
        break;
    case APP_OPS:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            setField(field, forWho, context.getSystemService(Context.APP_OPS_SERVICE));
        }
        break;
    case BITMAP:
        setField(field, forWho, BitmapFactory.decodeResource(resources, idRes, null));
        break;
    }
}

From source file:com.android.car.trust.CarBleTrustAgent.java

private void unlock(byte[] token, long handle) {
    UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);

    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "About to unlock user. Current handle: " + handle + " Time: " + System.currentTimeMillis());
    }//from  w ww.  j a  v a2s.  c  o  m
    unlockUserWithToken(handle, token, getCurrentUserHandle());

    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "Attempted to unlock user, is user unlocked? " + um.isUserUnlocked() + " Time: "
                + System.currentTimeMillis());
    }
    setManagingTrust(true);

    if (um.isUserUnlocked()) {
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, getString(R.string.trust_granted_explanation));
        }
        grantTrust("Granting trust from escrow token", TRUST_DURATION_MS, FLAG_GRANT_TRUST_DISMISS_KEYGUARD);
        // Trust has been granted, disable the BLE server. This trust agent service does
        // not need to receive additional BLE data.
        unbindService(mServiceConnection);
    }
}

From source file:com.android.tv.settings.users.AppRestrictionsFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null) {
        mUser = new UserHandle(savedInstanceState.getInt(EXTRA_USER_ID));
    } else {/* w  w w  .ja va2s .com*/
        Bundle args = getArguments();
        if (args != null) {
            if (args.containsKey(EXTRA_USER_ID)) {
                mUser = new UserHandle(args.getInt(EXTRA_USER_ID));
            }
            mNewUser = args.getBoolean(EXTRA_NEW_USER, false);
        }
    }

    if (mUser == null) {
        mUser = android.os.Process.myUserHandle();
    }

    mHelper = new AppRestrictionsHelper(getContext(), mUser);
    mHelper.setLeanback(true);
    mPackageManager = getActivity().getPackageManager();
    mIPm = AppGlobals.getPackageManager();
    mUserManager = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
    mRestrictedProfile = mUserManager.getUserInfo(mUser.getIdentifier()).isRestricted();
    try {
        mSysPackageInfo = mPackageManager.getPackageInfo("android", PackageManager.GET_SIGNATURES);
    } catch (PackageManager.NameNotFoundException nnfe) {
        Log.e(TAG, "Could not find system package signatures", nnfe);
    }
    mAppList = getAppPreferenceGroup();
    mAppList.setOrderingAsAdded(false);
}

From source file:com.android.managedprovisioning.ProfileOwnerPreProvisioningActivity.java

/**
 * @return The User id of an already existing managed profile or -1 if none
 * exists//from   w ww.  j  a va2  s .com
 */
int alreadyHasManagedProfile() {
    UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
    List<UserInfo> profiles = userManager.getProfiles(getUserId());
    for (UserInfo userInfo : profiles) {
        if (userInfo.isManagedProfile()) {
            return userInfo.getUserHandle().getIdentifier();
        }
    }
    return -1;
}

From source file:com.android.managedprovisioning.ProfileOwnerPreProvisioningActivity.java

/**
 * Builds a dialog that allows the user to remove an existing managed profile after they were
 * shown an additional warning./*from w  w  w .ja v  a 2 s .com*/
 */
private void showManagedProfileExistsDialog(final int existingManagedProfileUserId) {

    // Before deleting, show a warning dialog
    DialogInterface.OnClickListener warningListener = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // Really delete the profile if the user clicks delete on the warning dialog.
            final DialogInterface.OnClickListener deleteListener = new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
                    userManager.removeUser(existingManagedProfileUserId);
                    showStartProvisioningScreen();
                }
            };
            buildDeleteManagedProfileDialog(getString(R.string.sure_you_want_to_delete_profile), deleteListener)
                    .show();
        }
    };

    buildDeleteManagedProfileDialog(getString(R.string.managed_profile_already_present), warningListener)
            .show();
}