Add background image for work challenge
If the challenge shown is for a work profile, add the default image and color to the background of the fragment. Change-Id: I148c6cd3a835a84c7bac78b020839dfdae4a6c36
This commit is contained in:
@@ -172,7 +172,7 @@ public class ChooseLockGeneric extends SettingsActivity {
|
||||
!mLockPatternUtils.isSeparateProfileChallengeAllowed(targetUser)) {
|
||||
// Always use parent if explicitely requested or if profile challenge is not
|
||||
// supported
|
||||
mUserId = Utils.getSameOwnerUserId(getContext(), getArguments());
|
||||
mUserId = Utils.getUserIdFromBundle(getContext(), getArguments());
|
||||
} else {
|
||||
mUserId = targetUser;
|
||||
}
|
||||
|
@@ -238,7 +238,7 @@ public class ChooseLockPassword extends SettingsActivity {
|
||||
throw new SecurityException("Fragment contained in wrong activity");
|
||||
}
|
||||
// Only take this argument into account if it belongs to the current profile.
|
||||
mUserId = Utils.getSameOwnerUserId(getActivity(), intent.getExtras());
|
||||
mUserId = Utils.getUserIdFromBundle(getActivity(), intent.getExtras());
|
||||
mRequestedQuality = Math.max(intent.getIntExtra(LockPatternUtils.PASSWORD_TYPE_KEY,
|
||||
mRequestedQuality), mLockPatternUtils.getRequestedPasswordQuality(
|
||||
mUserId));
|
||||
|
@@ -370,7 +370,7 @@ public class ChooseLockPattern extends SettingsActivity {
|
||||
}
|
||||
Intent intent = getActivity().getIntent();
|
||||
// Only take this argument into account if it belongs to the current profile.
|
||||
mUserId = Utils.getSameOwnerUserId(getActivity(), intent.getExtras());
|
||||
mUserId = Utils.getUserIdFromBundle(getActivity(), intent.getExtras());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -90,7 +90,7 @@ public final class ChooseLockSettingsHelper {
|
||||
boolean launchConfirmationActivity(int request, CharSequence title, boolean returnCredentials,
|
||||
int userId) {
|
||||
return launchConfirmationActivity(request, title, null, null,
|
||||
returnCredentials, false, false, 0, Utils.getSameOwnerUserId(mActivity, userId));
|
||||
returnCredentials, false, false, 0, Utils.enforceSameOwner(mActivity, userId));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,7 +110,7 @@ public final class ChooseLockSettingsHelper {
|
||||
@Nullable CharSequence header, @Nullable CharSequence description,
|
||||
boolean returnCredentials, boolean external) {
|
||||
return launchConfirmationActivity(request, title, header, description,
|
||||
returnCredentials, external, false, 0, Utils.getEffectiveUserId(mActivity));
|
||||
returnCredentials, external, false, 0, Utils.getCredentialOwnerUserId(mActivity));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,7 +131,7 @@ public final class ChooseLockSettingsHelper {
|
||||
@Nullable CharSequence header, @Nullable CharSequence description,
|
||||
boolean returnCredentials, boolean external, int userId) {
|
||||
return launchConfirmationActivity(request, title, header, description,
|
||||
returnCredentials, external, false, 0, Utils.getSameOwnerUserId(mActivity, userId));
|
||||
returnCredentials, external, false, 0, Utils.enforceSameOwner(mActivity, userId));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -147,7 +147,7 @@ public final class ChooseLockSettingsHelper {
|
||||
@Nullable CharSequence header, @Nullable CharSequence description,
|
||||
long challenge) {
|
||||
return launchConfirmationActivity(request, title, header, description,
|
||||
false, false, true, challenge, Utils.getEffectiveUserId(mActivity));
|
||||
false, false, true, challenge, Utils.getCredentialOwnerUserId(mActivity));
|
||||
}
|
||||
|
||||
private boolean launchConfirmationActivity(int request, @Nullable CharSequence title,
|
||||
|
@@ -64,12 +64,12 @@ public class ConfirmDeviceCredentialActivity extends Activity {
|
||||
Intent intent = getIntent();
|
||||
String title = intent.getStringExtra(KeyguardManager.EXTRA_TITLE);
|
||||
String details = intent.getStringExtra(KeyguardManager.EXTRA_DESCRIPTION);
|
||||
int userId = Utils.getEffectiveUserId(this);
|
||||
int userId = Utils.getCredentialOwnerUserId(this);
|
||||
if (isInternalActivity()) {
|
||||
int givenUserId = intent.getIntExtra(Intent.EXTRA_USER_ID, userId);
|
||||
UserManager userManager = UserManager.get(this);
|
||||
if (userManager.isSameProfileGroup(givenUserId, userId)) {
|
||||
userId = givenUserId;
|
||||
try {
|
||||
userId = Utils.getUserIdFromBundle(this, intent.getExtras());
|
||||
} catch (SecurityException se) {
|
||||
Log.e(TAG, "Invalid intent extra", se);
|
||||
}
|
||||
}
|
||||
ChooseLockSettingsHelper helper = new ChooseLockSettingsHelper(this);
|
||||
|
@@ -18,8 +18,10 @@ package com.android.settings;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.app.KeyguardManager;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.UserManager;
|
||||
import android.view.MenuItem;
|
||||
import android.view.WindowManager;
|
||||
|
||||
@@ -33,7 +35,12 @@ public abstract class ConfirmDeviceCredentialBaseActivity extends SettingsActivi
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedState) {
|
||||
if (getIntent().getBooleanExtra(ConfirmDeviceCredentialBaseFragment.DARK_THEME, false)) {
|
||||
int credentialOwnerUserId = Utils.getCredentialOwnerUserId(this,
|
||||
Utils.getUserIdFromBundle(this, getIntent().getExtras()));
|
||||
if (Utils.isManagedProfile(UserManager.get(this), credentialOwnerUserId)) {
|
||||
setTheme(R.style.Theme_ConfirmDeviceCredentialsWork);
|
||||
} else if (getIntent().getBooleanExtra(
|
||||
ConfirmDeviceCredentialBaseFragment.DARK_THEME, false)) {
|
||||
setTheme(R.style.Theme_ConfirmDeviceCredentialsDark);
|
||||
mDark = true;
|
||||
}
|
||||
|
@@ -24,10 +24,16 @@ import android.app.IActivityManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentSender;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserManager;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
@@ -80,6 +86,14 @@ public abstract class ConfirmDeviceCredentialBaseFragment extends InstrumentedFr
|
||||
getActivity().finish();
|
||||
}
|
||||
});
|
||||
int credentialOwnerUserId = Utils.getCredentialOwnerUserId(
|
||||
getActivity(),
|
||||
Utils.getUserIdFromBundle(
|
||||
getActivity(),
|
||||
getActivity().getIntent().getExtras()));
|
||||
if (Utils.isManagedProfile(UserManager.get(getActivity()), credentialOwnerUserId)) {
|
||||
setWorkChallengeBackground(view);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -155,4 +169,20 @@ public abstract class ConfirmDeviceCredentialBaseFragment extends InstrumentedFr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setWorkChallengeBackground(View baseView) {
|
||||
ImageView imageView = (ImageView) baseView.findViewById(R.id.background_image);
|
||||
if (imageView != null) {
|
||||
Drawable image = getResources().getDrawable(R.drawable.work_challenge_background);
|
||||
image.setColorFilter(
|
||||
getResources().getColor(R.color.confirm_device_credential_transparent_black),
|
||||
PorterDuff.Mode.DARKEN);
|
||||
imageView.setImageDrawable(image);
|
||||
Point screenSize = new Point();
|
||||
getActivity().getWindowManager().getDefaultDisplay().getSize(screenSize);
|
||||
imageView.setLayoutParams(new FrameLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
screenSize.y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -111,7 +111,7 @@ public class ConfirmLockPassword extends ConfirmDeviceCredentialBaseActivity {
|
||||
mLockPatternUtils = new LockPatternUtils(getActivity());
|
||||
Intent intent = getActivity().getIntent();
|
||||
// Only take this argument into account if it belongs to the current profile.
|
||||
mEffectiveUserId = Utils.getSameOwnerUserId(getActivity(), intent.getExtras());
|
||||
mEffectiveUserId = Utils.getUserIdFromBundle(getActivity(), intent.getExtras());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -116,7 +116,7 @@ public class ConfirmLockPattern extends ConfirmDeviceCredentialBaseActivity {
|
||||
mLockPatternUtils = new LockPatternUtils(getActivity());
|
||||
Intent intent = getActivity().getIntent();
|
||||
// Only take this argument into account if it belongs to the current profile.
|
||||
mEffectiveUserId = Utils.getSameOwnerUserId(getActivity(), intent.getExtras());
|
||||
mEffectiveUserId = Utils.getUserIdFromBundle(getActivity(), intent.getExtras());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settings;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.ActivityManagerNative;
|
||||
@@ -180,6 +181,19 @@ public final class Utils extends com.android.settingslib.Utils {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the UserManager for a given context
|
||||
*
|
||||
* @throws IllegalStateException if no UserManager could be retrieved.
|
||||
*/
|
||||
public static UserManager getUserManager(Context context) {
|
||||
UserManager um = UserManager.get(context);
|
||||
if (um == null) {
|
||||
throw new IllegalStateException("Unable to load UserManager");
|
||||
}
|
||||
return um;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if Monkey is running.
|
||||
*/
|
||||
@@ -569,10 +583,24 @@ public final class Utils extends com.android.settingslib.Utils {
|
||||
|
||||
/**
|
||||
* Returns true if the current profile is a managed one.
|
||||
*
|
||||
* @throws IllegalArgumentException if userManager is null.
|
||||
*/
|
||||
public static boolean isManagedProfile(UserManager userManager) {
|
||||
UserInfo currentUser = userManager.getUserInfo(userManager.getUserHandle());
|
||||
return currentUser.isManagedProfile();
|
||||
public static boolean isManagedProfile(@NonNull UserManager userManager) {
|
||||
return isManagedProfile(userManager, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the userId passed in is a managed profile.
|
||||
*
|
||||
* @throws IllegalArgumentException if userManager is null.
|
||||
*/
|
||||
public static boolean isManagedProfile(@NonNull UserManager userManager, int userId) {
|
||||
if (userManager == null) {
|
||||
throw new IllegalArgumentException("userManager must not be null");
|
||||
}
|
||||
UserInfo userInfo = userManager.getUserInfo(userId);
|
||||
return (userInfo != null) ? userInfo.isManagedProfile() : false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -932,17 +960,17 @@ public final class Utils extends com.android.settingslib.Utils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the user id present in the bundle with {@link ChooseLockGeneric#KEY_USER_ID} if it
|
||||
* Returns the user id present in the bundle with {@link Intent#EXTRA_USER_ID} if it
|
||||
* belongs to the current user.
|
||||
*
|
||||
* @throws SecurityException if the given userId does not belong to the current user group.
|
||||
*/
|
||||
public static int getSameOwnerUserId(Context context, Bundle bundle) {
|
||||
public static int getUserIdFromBundle(Context context, Bundle bundle) {
|
||||
if (bundle == null) {
|
||||
return getEffectiveUserId(context);
|
||||
return getCredentialOwnerUserId(context);
|
||||
}
|
||||
int userId = bundle.getInt(Intent.EXTRA_USER_ID, UserHandle.myUserId());
|
||||
return getSameOwnerUserId(context, userId);
|
||||
return enforceSameOwner(context, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -950,27 +978,28 @@ public final class Utils extends com.android.settingslib.Utils {
|
||||
*
|
||||
* @throws SecurityException if the given userId does not belong to the current user group.
|
||||
*/
|
||||
public static int getSameOwnerUserId(Context context, int userId) {
|
||||
UserManager um = UserManager.get(context);
|
||||
if (um != null) {
|
||||
if (um.getUserProfiles().contains(new UserHandle(userId))) {
|
||||
return userId;
|
||||
} else {
|
||||
throw new SecurityException("Given user id " + userId + " does not belong to user "
|
||||
+ UserHandle.myUserId());
|
||||
}
|
||||
public static int enforceSameOwner(Context context, int userId) {
|
||||
UserManager um = getUserManager(context);
|
||||
if (!um.getUserProfiles().contains(new UserHandle(userId))) {
|
||||
throw new SecurityException("Given user id " + userId + " does not belong to user "
|
||||
+ UserHandle.myUserId());
|
||||
}
|
||||
return getEffectiveUserId(context);
|
||||
return userId;
|
||||
}
|
||||
|
||||
public static int getEffectiveUserId(Context context) {
|
||||
UserManager um = UserManager.get(context);
|
||||
if (um != null) {
|
||||
return um.getCredentialOwnerProfile(UserHandle.myUserId());
|
||||
} else {
|
||||
Log.e(TAG, "Unable to acquire UserManager");
|
||||
return UserHandle.myUserId();
|
||||
}
|
||||
/**
|
||||
* Returns the effective credential owner of the calling user.
|
||||
*/
|
||||
public static int getCredentialOwnerUserId(Context context) {
|
||||
return getCredentialOwnerUserId(context, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the user id of the credential owner of the given user id.
|
||||
*/
|
||||
public static int getCredentialOwnerUserId(Context context, int userId) {
|
||||
UserManager um = getUserManager(context);
|
||||
return um.getCredentialOwnerProfile(userId);
|
||||
}
|
||||
|
||||
public static int resolveResource(Context context, int attr) {
|
||||
|
Reference in New Issue
Block a user