Require work profile to be unlocked for changing notification settings in a different way

Rather than check for the state of the work profile in
LockScreenNotificationPreferenceController#handlePreferenceTreeClick, do so in
the RestrictedListPreference#performClick.
The drawback of checking the state in handlePreferenceTreeClick is that the
preferences are displayed first and then the requirement to unlock/enable the
work profile is displayed on top of it.

This is rather poor UX, so switch to doing the check in performClick and
returning early if the work profile needs to be unlocked/enabled.
This is similar to Patchset 1 from ag/3805482.
The main difference is that the user is returned to the settings screen
both after enabling the work profile and unlocking it.

Test: Manually with TestDPC
Test: atest SettingsRoboTests:RestrictedListPreferenceTest
Bug: 77408805
Merged-In: Id168911b082fffac193cd7c7a658ab92d6ce2c15
Change-Id: I0a3a4ec4dda78e28ee88a11d383eda49e9cf50a6
This commit is contained in:
Eran Messeri
2018-04-02 23:10:00 +03:00
parent d940a680a5
commit f61ccf3fa3
4 changed files with 173 additions and 38 deletions

View File

@@ -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 =