Search in sources :

Example 96 with UserManager

use of android.os.UserManager in project platform_frameworks_base by android.

the class LockSettingsStorageTests method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    mStorageDir = new File(getContext().getFilesDir(), "locksettings");
    mDb = getContext().getDatabasePath("locksettings.db");
    assertTrue(mStorageDir.exists() || mStorageDir.mkdirs());
    assertTrue(FileUtils.deleteContents(mStorageDir));
    assertTrue(!mDb.exists() || mDb.delete());
    final Context ctx = getContext();
    setContext(new ContextWrapper(ctx) {

        @Override
        public Object getSystemService(String name) {
            if (USER_SERVICE.equals(name)) {
                return new UserManager(ctx, null) {

                    @Override
                    public UserInfo getProfileParent(int userHandle) {
                        if (userHandle == 2) {
                            // User 2 is a profile of user 1.
                            return new UserInfo(1, "name", 0);
                        }
                        if (userHandle == 3) {
                            // User 3 is a profile of user 0.
                            return new UserInfo(0, "name", 0);
                        }
                        return null;
                    }
                };
            }
            return super.getSystemService(name);
        }
    });
    mStorage = new LockSettingsStorage(getContext(), new LockSettingsStorage.Callback() {

        @Override
        public void initialize(SQLiteDatabase db) {
            mStorage.writeKeyValue(db, "initializedKey", "initialValue", 0);
        }
    }) {

        @Override
        String getLockPatternFilename(int userId) {
            return new File(mStorageDir, super.getLockPatternFilename(userId).replace('/', '-')).getAbsolutePath();
        }

        @Override
        String getLockPasswordFilename(int userId) {
            return new File(mStorageDir, super.getLockPasswordFilename(userId).replace('/', '-')).getAbsolutePath();
        }

        @Override
        String getChildProfileLockFile(int userId) {
            return new File(mStorageDir, super.getChildProfileLockFile(userId).replace('/', '-')).getAbsolutePath();
        }
    };
}
Also used : Context(android.content.Context) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) UserManager(android.os.UserManager) UserInfo(android.content.pm.UserInfo) File(java.io.File) ContextWrapper(android.content.ContextWrapper)

Example 97 with UserManager

use of android.os.UserManager in project platform_frameworks_base by android.

the class ActivityTestMain method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.i(TAG, "Referrer: " + getReferrer());
    mAm = getSystemService(ActivityManager.class);
    mPower = getSystemService(PowerManager.class);
    mAlarm = getSystemService(AlarmManager.class);
    if (savedInstanceState != null) {
        mOverrideConfig = savedInstanceState.getParcelable(KEY_CONFIGURATION);
        if (mOverrideConfig != null) {
            applyOverrideConfiguration(mOverrideConfig);
        }
    }
    UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
    List<UserInfo> users = um.getUsers();
    mSecondUser = Integer.MAX_VALUE;
    for (UserInfo ui : users) {
        if (ui.id != 0 && mSecondUser > ui.id) {
            mSecondUser = ui.id;
        }
    }
/*
        AlertDialog ad = new AlertDialog.Builder(this).setTitle("title").setMessage("message").create();
        ad.getWindow().getAttributes().type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
        ad.show();
        */
}
Also used : PowerManager(android.os.PowerManager) UserManager(android.os.UserManager) AlarmManager(android.app.AlarmManager) UserInfo(android.content.pm.UserInfo) ActivityManager(android.app.ActivityManager)

Example 98 with UserManager

use of android.os.UserManager in project platform_frameworks_base by android.

the class ResolverActivity method setProfileSwitchMessageId.

private void setProfileSwitchMessageId(int contentUserHint) {
    if (contentUserHint != UserHandle.USER_CURRENT && contentUserHint != UserHandle.myUserId()) {
        UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
        UserInfo originUserInfo = userManager.getUserInfo(contentUserHint);
        boolean originIsManaged = originUserInfo != null ? originUserInfo.isManagedProfile() : false;
        boolean targetIsManaged = userManager.isManagedProfile();
        if (originIsManaged && !targetIsManaged) {
            mProfileSwitchMessageId = com.android.internal.R.string.forward_intent_to_owner;
        } else if (!originIsManaged && targetIsManaged) {
            mProfileSwitchMessageId = com.android.internal.R.string.forward_intent_to_work;
        }
    }
}
Also used : UserManager(android.os.UserManager) UserInfo(android.content.pm.UserInfo)

Example 99 with UserManager

use of android.os.UserManager in project platform_frameworks_base by android.

the class IntentForwarderActivity method getProfileParent.

/**
     * Returns the userId of the profile parent or UserHandle.USER_NULL if there is
     * no parent.
     */
private int getProfileParent() {
    UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
    UserInfo parent = userManager.getProfileParent(UserHandle.myUserId());
    if (parent == null) {
        Slog.wtf(TAG, FORWARD_INTENT_TO_PARENT + " has been called, but there is no parent");
        return UserHandle.USER_NULL;
    }
    return parent.id;
}
Also used : UserManager(android.os.UserManager) UserInfo(android.content.pm.UserInfo)

Example 100 with UserManager

use of android.os.UserManager in project android_frameworks_base by crdroidandroid.

the class RecoverySystem method rebootWipeUserData.

/**
     * Reboots the device and wipes the user data and cache
     * partitions.  This is sometimes called a "factory reset", which
     * is something of a misnomer because the system partition is not
     * restored to its factory state.  Requires the
     * {@link android.Manifest.permission#REBOOT} permission.
     *
     * @param context   the Context to use
     * @param shutdown  if true, the device will be powered down after
     *                  the wipe completes, rather than being rebooted
     *                  back to the regular system.
     * @param reason    the reason for the wipe that is visible in the logs
     * @param force     whether the {@link UserManager.DISALLOW_FACTORY_RESET} user restriction
     *                  should be ignored
     *
     * @throws IOException  if writing the recovery command file
     * fails, or if the reboot itself fails.
     * @throws SecurityException if the current user is not allowed to wipe data.
     *
     * @hide
     */
public static void rebootWipeUserData(Context context, boolean shutdown, String reason, boolean force) throws IOException {
    UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
    if (!force && um.hasUserRestriction(UserManager.DISALLOW_FACTORY_RESET)) {
        throw new SecurityException("Wiping data is not allowed for this user.");
    }
    final ConditionVariable condition = new ConditionVariable();
    Intent intent = new Intent("android.intent.action.MASTER_CLEAR_NOTIFICATION");
    intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    context.sendOrderedBroadcastAsUser(intent, UserHandle.SYSTEM, android.Manifest.permission.MASTER_CLEAR, new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            condition.open();
        }
    }, null, 0, null, null);
    // Block until the ordered broadcast has completed.
    condition.block();
    String shutdownArg = null;
    if (shutdown) {
        shutdownArg = "--shutdown_after";
    }
    String reasonArg = null;
    if (!TextUtils.isEmpty(reason)) {
        reasonArg = "--reason=" + sanitizeArg(reason);
    }
    final String localeArg = "--locale=" + Locale.getDefault().toString();
    bootCommand(context, shutdownArg, "--wipe_data", reasonArg, localeArg);
}
Also used : Context(android.content.Context) UserManager(android.os.UserManager) GeneralSecurityException(java.security.GeneralSecurityException) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Aggregations

UserManager (android.os.UserManager)587 UserInfo (android.content.pm.UserInfo)209 UserHandle (android.os.UserHandle)83 Context (android.content.Context)75 Intent (android.content.Intent)67 Test (org.junit.Test)60 PackageManager (android.content.pm.PackageManager)59 ComponentName (android.content.ComponentName)54 RemoteException (android.os.RemoteException)54 View (android.view.View)54 ArrayList (java.util.ArrayList)50 DevicePolicyManager (android.app.admin.DevicePolicyManager)37 Preference (android.support.v7.preference.Preference)32 TextView (android.widget.TextView)31 ImageView (android.widget.ImageView)29 IOException (java.io.IOException)29 Bitmap (android.graphics.Bitmap)26 Bundle (android.os.Bundle)25 ShadowUserManager (com.android.settings.testutils.shadow.ShadowUserManager)25 EnforcedAdmin (com.android.settingslib.RestrictedLockUtils.EnforcedAdmin)24