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:
BIN
res/drawable-nodpi/work_challenge_background.png
Normal file
BIN
res/drawable-nodpi/work_challenge_background.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 243 KiB |
@@ -13,11 +13,18 @@
|
|||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
<LinearLayout
|
<FrameLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" >
|
||||||
|
|
||||||
|
<include layout="@layout/confirm_lock_background_base" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@+id/topLayout"
|
android:id="@+id/topLayout"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@@ -90,4 +97,5 @@
|
|||||||
android:visibility="gone"/>
|
android:visibility="gone"/>
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
</FrameLayout>
|
@@ -13,7 +13,14 @@
|
|||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
<com.android.internal.widget.LinearLayoutWithDefaultTouchRecepient
|
<FrameLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" >
|
||||||
|
|
||||||
|
<include layout="@layout/confirm_lock_background_base" />
|
||||||
|
|
||||||
|
<com.android.internal.widget.LinearLayoutWithDefaultTouchRecepient
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@+id/topLayout"
|
android:id="@+id/topLayout"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
@@ -111,5 +118,5 @@
|
|||||||
android:visibility="gone"/>
|
android:visibility="gone"/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</com.android.internal.widget.LinearLayoutWithDefaultTouchRecepient>
|
</com.android.internal.widget.LinearLayoutWithDefaultTouchRecepient>
|
||||||
|
</FrameLayout>
|
21
res/layout/confirm_lock_background_base.xml
Normal file
21
res/layout/confirm_lock_background_base.xml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2016 The Android Open Source Project
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
<ImageView
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/background_image"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:scaleType="centerCrop" />
|
@@ -13,11 +13,18 @@
|
|||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
<com.android.internal.widget.LinearLayoutWithDefaultTouchRecepient
|
<FrameLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" >
|
||||||
|
|
||||||
|
<include layout="@layout/confirm_lock_background_base" />
|
||||||
|
|
||||||
|
<com.android.internal.widget.LinearLayoutWithDefaultTouchRecepient
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@+id/topLayout"
|
android:id="@+id/topLayout"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@@ -88,4 +95,5 @@
|
|||||||
android:contentDescription="@string/confirm_fingerprint_icon_content_description"
|
android:contentDescription="@string/confirm_fingerprint_icon_content_description"
|
||||||
android:visibility="gone"/>
|
android:visibility="gone"/>
|
||||||
|
|
||||||
</com.android.internal.widget.LinearLayoutWithDefaultTouchRecepient>
|
</com.android.internal.widget.LinearLayoutWithDefaultTouchRecepient>
|
||||||
|
</FrameLayout>
|
@@ -13,11 +13,18 @@
|
|||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
<com.android.internal.widget.LinearLayoutWithDefaultTouchRecepient
|
<FrameLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" >
|
||||||
|
|
||||||
|
<include layout="@layout/confirm_lock_background_base" />
|
||||||
|
|
||||||
|
<com.android.internal.widget.LinearLayoutWithDefaultTouchRecepient
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@+id/topLayout"
|
android:id="@+id/topLayout"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@@ -92,4 +99,5 @@
|
|||||||
android:visibility="gone"/>
|
android:visibility="gone"/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</com.android.internal.widget.LinearLayoutWithDefaultTouchRecepient>
|
</com.android.internal.widget.LinearLayoutWithDefaultTouchRecepient>
|
||||||
|
</FrameLayout>
|
@@ -82,6 +82,7 @@
|
|||||||
|
|
||||||
<color name="warning">#ff5621</color>
|
<color name="warning">#ff5621</color>
|
||||||
<color name="confirm_device_credential_dark_background">#263238</color>
|
<color name="confirm_device_credential_dark_background">#263238</color>
|
||||||
|
<color name="confirm_device_credential_transparent_black">#60000000</color>
|
||||||
<color name="fab_ripple">#1fffffff</color><!-- 12% white -->
|
<color name="fab_ripple">#1fffffff</color><!-- 12% white -->
|
||||||
<color name="fab_shape">?android:attr/colorAccent</color>
|
<color name="fab_shape">?android:attr/colorAccent</color>
|
||||||
<color name="voice_interaction_highlight">#33b5e5</color>
|
<color name="voice_interaction_highlight">#33b5e5</color>
|
||||||
|
@@ -255,6 +255,9 @@
|
|||||||
|
|
||||||
<item name="android:windowAnimationStyle">@style/ConfirmDeviceCredentialsAnimationStyle</item>
|
<item name="android:windowAnimationStyle">@style/ConfirmDeviceCredentialsAnimationStyle</item>
|
||||||
</style>
|
</style>
|
||||||
|
<style name="Theme.ConfirmDeviceCredentialsWork" parent="Theme.ConfirmDeviceCredentialsDark">
|
||||||
|
<item name="@*android:regularColor">@*android:color/white</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
<style name="Theme.FingerprintEnroll" parent="@*android:style/Theme.Material.Settings.NoActionBar">
|
<style name="Theme.FingerprintEnroll" parent="@*android:style/Theme.Material.Settings.NoActionBar">
|
||||||
<item name="android:windowAnimationStyle">@style/Animation.SuwWindowAnimation</item>
|
<item name="android:windowAnimationStyle">@style/Animation.SuwWindowAnimation</item>
|
||||||
|
@@ -172,7 +172,7 @@ public class ChooseLockGeneric extends SettingsActivity {
|
|||||||
!mLockPatternUtils.isSeparateProfileChallengeAllowed(targetUser)) {
|
!mLockPatternUtils.isSeparateProfileChallengeAllowed(targetUser)) {
|
||||||
// Always use parent if explicitely requested or if profile challenge is not
|
// Always use parent if explicitely requested or if profile challenge is not
|
||||||
// supported
|
// supported
|
||||||
mUserId = Utils.getSameOwnerUserId(getContext(), getArguments());
|
mUserId = Utils.getUserIdFromBundle(getContext(), getArguments());
|
||||||
} else {
|
} else {
|
||||||
mUserId = targetUser;
|
mUserId = targetUser;
|
||||||
}
|
}
|
||||||
|
@@ -238,7 +238,7 @@ public class ChooseLockPassword extends SettingsActivity {
|
|||||||
throw new SecurityException("Fragment contained in wrong activity");
|
throw new SecurityException("Fragment contained in wrong activity");
|
||||||
}
|
}
|
||||||
// Only take this argument into account if it belongs to the current profile.
|
// 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 = Math.max(intent.getIntExtra(LockPatternUtils.PASSWORD_TYPE_KEY,
|
||||||
mRequestedQuality), mLockPatternUtils.getRequestedPasswordQuality(
|
mRequestedQuality), mLockPatternUtils.getRequestedPasswordQuality(
|
||||||
mUserId));
|
mUserId));
|
||||||
|
@@ -370,7 +370,7 @@ public class ChooseLockPattern extends SettingsActivity {
|
|||||||
}
|
}
|
||||||
Intent intent = getActivity().getIntent();
|
Intent intent = getActivity().getIntent();
|
||||||
// Only take this argument into account if it belongs to the current profile.
|
// 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
|
@Override
|
||||||
|
@@ -90,7 +90,7 @@ public final class ChooseLockSettingsHelper {
|
|||||||
boolean launchConfirmationActivity(int request, CharSequence title, boolean returnCredentials,
|
boolean launchConfirmationActivity(int request, CharSequence title, boolean returnCredentials,
|
||||||
int userId) {
|
int userId) {
|
||||||
return launchConfirmationActivity(request, title, null, null,
|
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,
|
@Nullable CharSequence header, @Nullable CharSequence description,
|
||||||
boolean returnCredentials, boolean external) {
|
boolean returnCredentials, boolean external) {
|
||||||
return launchConfirmationActivity(request, title, header, description,
|
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,
|
@Nullable CharSequence header, @Nullable CharSequence description,
|
||||||
boolean returnCredentials, boolean external, int userId) {
|
boolean returnCredentials, boolean external, int userId) {
|
||||||
return launchConfirmationActivity(request, title, header, description,
|
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,
|
@Nullable CharSequence header, @Nullable CharSequence description,
|
||||||
long challenge) {
|
long challenge) {
|
||||||
return launchConfirmationActivity(request, title, header, description,
|
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,
|
private boolean launchConfirmationActivity(int request, @Nullable CharSequence title,
|
||||||
|
@@ -64,12 +64,12 @@ public class ConfirmDeviceCredentialActivity extends Activity {
|
|||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
String title = intent.getStringExtra(KeyguardManager.EXTRA_TITLE);
|
String title = intent.getStringExtra(KeyguardManager.EXTRA_TITLE);
|
||||||
String details = intent.getStringExtra(KeyguardManager.EXTRA_DESCRIPTION);
|
String details = intent.getStringExtra(KeyguardManager.EXTRA_DESCRIPTION);
|
||||||
int userId = Utils.getEffectiveUserId(this);
|
int userId = Utils.getCredentialOwnerUserId(this);
|
||||||
if (isInternalActivity()) {
|
if (isInternalActivity()) {
|
||||||
int givenUserId = intent.getIntExtra(Intent.EXTRA_USER_ID, userId);
|
try {
|
||||||
UserManager userManager = UserManager.get(this);
|
userId = Utils.getUserIdFromBundle(this, intent.getExtras());
|
||||||
if (userManager.isSameProfileGroup(givenUserId, userId)) {
|
} catch (SecurityException se) {
|
||||||
userId = givenUserId;
|
Log.e(TAG, "Invalid intent extra", se);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ChooseLockSettingsHelper helper = new ChooseLockSettingsHelper(this);
|
ChooseLockSettingsHelper helper = new ChooseLockSettingsHelper(this);
|
||||||
|
@@ -18,8 +18,10 @@ package com.android.settings;
|
|||||||
|
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.app.KeyguardManager;
|
import android.app.KeyguardManager;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.os.UserManager;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
|
||||||
@@ -33,7 +35,12 @@ public abstract class ConfirmDeviceCredentialBaseActivity extends SettingsActivi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedState) {
|
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);
|
setTheme(R.style.Theme_ConfirmDeviceCredentialsDark);
|
||||||
mDark = true;
|
mDark = true;
|
||||||
}
|
}
|
||||||
|
@@ -24,10 +24,16 @@ import android.app.IActivityManager;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentSender;
|
import android.content.IntentSender;
|
||||||
|
import android.graphics.Point;
|
||||||
|
import android.graphics.PorterDuff;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
|
import android.os.UserManager;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
@@ -80,6 +86,14 @@ public abstract class ConfirmDeviceCredentialBaseFragment extends InstrumentedFr
|
|||||||
getActivity().finish();
|
getActivity().finish();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
int credentialOwnerUserId = Utils.getCredentialOwnerUserId(
|
||||||
|
getActivity(),
|
||||||
|
Utils.getUserIdFromBundle(
|
||||||
|
getActivity(),
|
||||||
|
getActivity().getIntent().getExtras()));
|
||||||
|
if (Utils.isManagedProfile(UserManager.get(getActivity()), credentialOwnerUserId)) {
|
||||||
|
setWorkChallengeBackground(view);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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());
|
mLockPatternUtils = new LockPatternUtils(getActivity());
|
||||||
Intent intent = getActivity().getIntent();
|
Intent intent = getActivity().getIntent();
|
||||||
// Only take this argument into account if it belongs to the current profile.
|
// 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
|
@Override
|
||||||
|
@@ -116,7 +116,7 @@ public class ConfirmLockPattern extends ConfirmDeviceCredentialBaseActivity {
|
|||||||
mLockPatternUtils = new LockPatternUtils(getActivity());
|
mLockPatternUtils = new LockPatternUtils(getActivity());
|
||||||
Intent intent = getActivity().getIntent();
|
Intent intent = getActivity().getIntent();
|
||||||
// Only take this argument into account if it belongs to the current profile.
|
// 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
|
@Override
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.settings;
|
package com.android.settings;
|
||||||
|
|
||||||
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.app.ActivityManagerNative;
|
import android.app.ActivityManagerNative;
|
||||||
@@ -180,6 +181,19 @@ public final class Utils extends com.android.settingslib.Utils {
|
|||||||
return false;
|
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.
|
* 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.
|
* Returns true if the current profile is a managed one.
|
||||||
|
*
|
||||||
|
* @throws IllegalArgumentException if userManager is null.
|
||||||
*/
|
*/
|
||||||
public static boolean isManagedProfile(UserManager userManager) {
|
public static boolean isManagedProfile(@NonNull UserManager userManager) {
|
||||||
UserInfo currentUser = userManager.getUserInfo(userManager.getUserHandle());
|
return isManagedProfile(userManager, UserHandle.myUserId());
|
||||||
return currentUser.isManagedProfile();
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
* belongs to the current user.
|
||||||
*
|
*
|
||||||
* @throws SecurityException if the given userId does not belong to the current user group.
|
* @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) {
|
if (bundle == null) {
|
||||||
return getEffectiveUserId(context);
|
return getCredentialOwnerUserId(context);
|
||||||
}
|
}
|
||||||
int userId = bundle.getInt(Intent.EXTRA_USER_ID, UserHandle.myUserId());
|
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.
|
* @throws SecurityException if the given userId does not belong to the current user group.
|
||||||
*/
|
*/
|
||||||
public static int getSameOwnerUserId(Context context, int userId) {
|
public static int enforceSameOwner(Context context, int userId) {
|
||||||
UserManager um = UserManager.get(context);
|
UserManager um = getUserManager(context);
|
||||||
if (um != null) {
|
if (!um.getUserProfiles().contains(new UserHandle(userId))) {
|
||||||
if (um.getUserProfiles().contains(new UserHandle(userId))) {
|
|
||||||
return userId;
|
|
||||||
} else {
|
|
||||||
throw new SecurityException("Given user id " + userId + " does not belong to user "
|
throw new SecurityException("Given user id " + userId + " does not belong to user "
|
||||||
+ UserHandle.myUserId());
|
+ UserHandle.myUserId());
|
||||||
}
|
}
|
||||||
}
|
return userId;
|
||||||
return getEffectiveUserId(context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getEffectiveUserId(Context context) {
|
/**
|
||||||
UserManager um = UserManager.get(context);
|
* Returns the effective credential owner of the calling user.
|
||||||
if (um != null) {
|
*/
|
||||||
return um.getCredentialOwnerProfile(UserHandle.myUserId());
|
public static int getCredentialOwnerUserId(Context context) {
|
||||||
} else {
|
return getCredentialOwnerUserId(context, UserHandle.myUserId());
|
||||||
Log.e(TAG, "Unable to acquire UserManager");
|
|
||||||
return 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) {
|
public static int resolveResource(Context context, int attr) {
|
||||||
|
Reference in New Issue
Block a user