Merge "Require work profile to be unlocked for changing notification settings in a different way" into pi-dev
This commit is contained in:
@@ -16,10 +16,16 @@
|
||||
|
||||
package com.android.settings;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.KeyguardManager;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserManager;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v14.preference.ListPreferenceDialogFragment;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.util.AttributeSet;
|
||||
@@ -32,6 +38,7 @@ import android.widget.ImageView;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedPreferenceHelper;
|
||||
|
||||
@@ -43,6 +50,8 @@ import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
public class RestrictedListPreference extends CustomListPreference {
|
||||
private final RestrictedPreferenceHelper mHelper;
|
||||
private final List<RestrictedItem> mRestrictedItems = new ArrayList<>();
|
||||
private boolean mRequiresActiveUnlockedProfile = false;
|
||||
private int mProfileUserId;
|
||||
|
||||
public RestrictedListPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
@@ -68,6 +77,24 @@ public class RestrictedListPreference extends CustomListPreference {
|
||||
|
||||
@Override
|
||||
public void performClick() {
|
||||
if (mRequiresActiveUnlockedProfile) {
|
||||
// Check if the profile is started, first.
|
||||
if (Utils.startQuietModeDialogIfNecessary(getContext(), UserManager.get(getContext()),
|
||||
mProfileUserId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Next, check if the profile is unlocked.
|
||||
KeyguardManager manager =
|
||||
(KeyguardManager) getContext().getSystemService(Context.KEYGUARD_SERVICE);
|
||||
if (manager.isDeviceLocked(mProfileUserId)) {
|
||||
Intent intent = manager.createConfirmDeviceCredentialIntent(
|
||||
null, null, mProfileUserId);
|
||||
getContext().startActivity(intent);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!mHelper.performClick()) {
|
||||
super.performClick();
|
||||
}
|
||||
@@ -92,6 +119,14 @@ public class RestrictedListPreference extends CustomListPreference {
|
||||
return mHelper.isDisabledByAdmin();
|
||||
}
|
||||
|
||||
public void setRequiresActiveUnlockedProfile(boolean reqState) {
|
||||
mRequiresActiveUnlockedProfile = reqState;
|
||||
}
|
||||
|
||||
public void setProfileUserId(int profileUserId) {
|
||||
mProfileUserId = profileUserId;
|
||||
}
|
||||
|
||||
public boolean isRestrictedForEntry(CharSequence entry) {
|
||||
if (entry == null) {
|
||||
return false;
|
||||
@@ -263,4 +298,4 @@ public class RestrictedListPreference extends CustomListPreference {
|
||||
this.enforcedAdmin = enforcedAdmin;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -19,16 +19,12 @@ package com.android.settings.notification;
|
||||
import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS;
|
||||
import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.app.KeyguardManager;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.ContentObserver;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
@@ -101,6 +97,8 @@ public class LockScreenNotificationPreferenceController extends AbstractPreferen
|
||||
}
|
||||
if (mProfileUserId != UserHandle.USER_NULL) {
|
||||
mLockscreenProfile = (RestrictedListPreference) screen.findPreference(mWorkSettingKey);
|
||||
mLockscreenProfile.setRequiresActiveUnlockedProfile(true);
|
||||
mLockscreenProfile.setProfileUserId(mProfileUserId);
|
||||
} else {
|
||||
setVisible(screen, mWorkSettingKey, false /* visible */);
|
||||
setVisible(screen, mWorkSettingCategoryKey, false /* visible */);
|
||||
@@ -244,39 +242,6 @@ public class LockScreenNotificationPreferenceController extends AbstractPreferen
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
final String key = preference.getKey();
|
||||
if (!TextUtils.equals(mWorkSettingKey, key)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if the profile is started, first.
|
||||
if (Utils.startQuietModeDialogIfNecessary(mContext, UserManager.get(mContext),
|
||||
mProfileUserId)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Next, check if the profile is unlocked.
|
||||
KeyguardManager manager =
|
||||
(KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);
|
||||
if (manager.isDeviceLocked(mProfileUserId)) {
|
||||
//TODO: Figure out how to return the user to the current activity so they
|
||||
//don't have to navigate to the settings again.
|
||||
Intent intent = manager.createConfirmDeviceCredentialIntent(
|
||||
null, null, mProfileUserId);
|
||||
try {
|
||||
ActivityManager.getService().startConfirmDeviceCredentialIntent(intent,
|
||||
null /*options*/);
|
||||
} catch (RemoteException ignored) {
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void setRestrictedIfNotificationFeaturesDisabled(CharSequence entry,
|
||||
CharSequence entryValue, int keyguardNotificationFeatures) {
|
||||
RestrictedLockUtils.EnforcedAdmin admin =
|
||||
|
Reference in New Issue
Block a user