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();
}
};
}
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();
*/
}
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;
}
}
}
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;
}
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);
}
Aggregations