am 23589caa: am 1d4ad01f: Merge "Volume: Hide zen options during setup." into lmp-dev
* commit '23589caa88bb5a7fde62a9edff4ac189e56b8ccb': Volume: Hide zen options during setup.
This commit is contained in:
@@ -29,11 +29,13 @@ public interface ZenModeController {
|
||||
Uri getExitConditionId();
|
||||
long getNextAlarm();
|
||||
void setUserId(int userId);
|
||||
boolean isZenAvailable();
|
||||
|
||||
public static class Callback {
|
||||
public void onZenChanged(int zen) {}
|
||||
public void onExitConditionChanged(Uri exitConditionId) {}
|
||||
public void onConditionsChanged(Condition[] conditions) {}
|
||||
public void onNextAlarmChanged() {}
|
||||
public void onZenAvailableChanged(boolean available) {}
|
||||
}
|
||||
}
|
||||
@@ -20,15 +20,18 @@ import android.app.AlarmClockInfo;
|
||||
import android.app.AlarmManager;
|
||||
import android.app.INotificationManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.database.ContentObserver;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings.Global;
|
||||
import android.provider.Settings.Secure;
|
||||
import android.service.notification.Condition;
|
||||
import android.service.notification.IConditionListener;
|
||||
import android.service.notification.ZenModeConfig;
|
||||
@@ -52,6 +55,7 @@ public class ZenModeControllerImpl implements ZenModeController {
|
||||
private final INotificationManager mNoMan;
|
||||
private final LinkedHashMap<Uri, Condition> mConditions = new LinkedHashMap<Uri, Condition>();
|
||||
private final AlarmManager mAlarmManager;
|
||||
private final SetupObserver mSetupObserver;
|
||||
|
||||
private int mUserId;
|
||||
private boolean mRequesting;
|
||||
@@ -76,6 +80,8 @@ public class ZenModeControllerImpl implements ZenModeController {
|
||||
mNoMan = INotificationManager.Stub.asInterface(
|
||||
ServiceManager.getService(Context.NOTIFICATION_SERVICE));
|
||||
mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
||||
mSetupObserver = new SetupObserver(handler);
|
||||
mSetupObserver.register();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -98,6 +104,11 @@ public class ZenModeControllerImpl implements ZenModeController {
|
||||
mModeSetting.setValue(zen);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isZenAvailable() {
|
||||
return mSetupObserver.isDeviceProvisioned() && mSetupObserver.isUserSetup();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestConditions(boolean request) {
|
||||
mRequesting = request;
|
||||
@@ -148,6 +159,7 @@ public class ZenModeControllerImpl implements ZenModeController {
|
||||
mContext.registerReceiverAsUser(mReceiver, new UserHandle(mUserId),
|
||||
new IntentFilter(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED), null, null);
|
||||
mRegistered = true;
|
||||
mSetupObserver.register();
|
||||
}
|
||||
|
||||
private void fireNextAlarmChanged() {
|
||||
@@ -162,6 +174,12 @@ public class ZenModeControllerImpl implements ZenModeController {
|
||||
}
|
||||
}
|
||||
|
||||
private void fireZenAvailableChanged(boolean available) {
|
||||
for (Callback cb : mCallbacks) {
|
||||
cb.onZenAvailableChanged(available);
|
||||
}
|
||||
}
|
||||
|
||||
private void fireConditionsChanged(Condition[] conditions) {
|
||||
for (Callback cb : mCallbacks) {
|
||||
cb.onConditionsChanged(conditions);
|
||||
@@ -204,4 +222,42 @@ public class ZenModeControllerImpl implements ZenModeController {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private final class SetupObserver extends ContentObserver {
|
||||
private final ContentResolver mResolver;
|
||||
|
||||
private boolean mRegistered;
|
||||
|
||||
public SetupObserver(Handler handler) {
|
||||
super(handler);
|
||||
mResolver = mContext.getContentResolver();
|
||||
}
|
||||
|
||||
public boolean isUserSetup() {
|
||||
return Secure.getIntForUser(mResolver, Secure.USER_SETUP_COMPLETE, 0, mUserId) != 0;
|
||||
}
|
||||
|
||||
public boolean isDeviceProvisioned() {
|
||||
return Global.getInt(mResolver, Global.DEVICE_PROVISIONED, 0) != 0;
|
||||
}
|
||||
|
||||
public void register() {
|
||||
if (mRegistered) {
|
||||
mResolver.unregisterContentObserver(this);
|
||||
}
|
||||
mResolver.registerContentObserver(
|
||||
Global.getUriFor(Global.DEVICE_PROVISIONED), false, this);
|
||||
mResolver.registerContentObserver(
|
||||
Secure.getUriFor(Secure.USER_SETUP_COMPLETE), false, this, mUserId);
|
||||
fireZenAvailableChanged(isZenAvailable());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange(boolean selfChange, Uri uri) {
|
||||
if (Global.getUriFor(Global.DEVICE_PROVISIONED).equals(uri)
|
||||
|| Secure.getUriFor(Secure.USER_SETUP_COMPLETE).equals(uri)) {
|
||||
fireZenAvailableChanged(isZenAvailable());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ public class VolumePanel extends Handler {
|
||||
private static final int MSG_SLIDER_VISIBILITY_CHANGED = 10;
|
||||
private static final int MSG_DISPLAY_SAFE_VOLUME_WARNING = 11;
|
||||
private static final int MSG_LAYOUT_DIRECTION = 12;
|
||||
private static final int MSG_ZEN_MODE_CHANGED = 13;
|
||||
private static final int MSG_ZEN_MODE_AVAILABLE_CHANGED = 13;
|
||||
private static final int MSG_USER_ACTIVITY = 14;
|
||||
|
||||
// Pseudo stream type for master volume
|
||||
@@ -125,7 +125,7 @@ public class VolumePanel extends Handler {
|
||||
private final ZenModeController mZenController;
|
||||
private boolean mRingIsSilent;
|
||||
private boolean mVoiceCapable;
|
||||
private boolean mZenModeCapable;
|
||||
private boolean mZenModeAvailable;
|
||||
private boolean mZenPanelExpanded;
|
||||
private int mTimeoutDelay = TIMEOUT_DELAY;
|
||||
private float mDisabledAlpha;
|
||||
@@ -405,9 +405,10 @@ public class VolumePanel extends Handler {
|
||||
mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
mVoiceCapable = context.getResources().getBoolean(R.bool.config_voice_capable);
|
||||
|
||||
mZenModeCapable = !useMasterVolume && mZenController != null;
|
||||
updateZenMode(mZenController != null ? mZenController.getZen() : Global.ZEN_MODE_OFF);
|
||||
mZenController.addCallback(mZenCallback);
|
||||
if (mZenController != null && !useMasterVolume) {
|
||||
mZenModeAvailable = mZenController.isZenAvailable();
|
||||
mZenController.addCallback(mZenCallback);
|
||||
}
|
||||
|
||||
final boolean masterVolumeOnly = res.getBoolean(R.bool.config_useMasterVolume);
|
||||
final boolean masterVolumeKeySounds = res.getBoolean(R.bool.config_useVolumeKeySounds);
|
||||
@@ -434,7 +435,7 @@ public class VolumePanel extends Handler {
|
||||
pw.print(" mTag="); pw.println(mTag);
|
||||
pw.print(" mRingIsSilent="); pw.println(mRingIsSilent);
|
||||
pw.print(" mVoiceCapable="); pw.println(mVoiceCapable);
|
||||
pw.print(" mZenModeCapable="); pw.println(mZenModeCapable);
|
||||
pw.print(" mZenModeAvailable="); pw.println(mZenModeAvailable);
|
||||
pw.print(" mZenPanelExpanded="); pw.println(mZenPanelExpanded);
|
||||
pw.print(" mTimeoutDelay="); pw.println(mTimeoutDelay);
|
||||
pw.print(" mDisabledAlpha="); pw.println(mDisabledAlpha);
|
||||
@@ -645,7 +646,7 @@ public class VolumePanel extends Handler {
|
||||
active.group.setVisibility(View.VISIBLE);
|
||||
updateSlider(active);
|
||||
updateTimeoutDelay();
|
||||
setZenPanelVisible(isNotificationOrRing(mActiveStreamType));
|
||||
updateZenPanelVisible();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -776,14 +777,8 @@ public class VolumePanel extends Handler {
|
||||
}
|
||||
}
|
||||
|
||||
private void updateZenMode(int zen) {
|
||||
final boolean show = mZenModeCapable && isNotificationOrRing(mActiveStreamType);
|
||||
setZenPanelVisible(show);
|
||||
}
|
||||
|
||||
public void postZenModeChanged(int zen) {
|
||||
removeMessages(MSG_ZEN_MODE_CHANGED);
|
||||
obtainMessage(MSG_ZEN_MODE_CHANGED, zen).sendToTarget();
|
||||
private void updateZenPanelVisible() {
|
||||
setZenPanelVisible(mZenModeAvailable && isNotificationOrRing(mActiveStreamType));
|
||||
}
|
||||
|
||||
public void postVolumeChanged(int streamType, int flags) {
|
||||
@@ -1307,8 +1302,9 @@ public class VolumePanel extends Handler {
|
||||
setLayoutDirection(msg.arg1);
|
||||
break;
|
||||
|
||||
case MSG_ZEN_MODE_CHANGED:
|
||||
updateZenMode(msg.arg1);
|
||||
case MSG_ZEN_MODE_AVAILABLE_CHANGED:
|
||||
mZenModeAvailable = msg.arg1 != 0;
|
||||
updateZenPanelVisible();
|
||||
break;
|
||||
|
||||
case MSG_USER_ACTIVITY:
|
||||
@@ -1359,8 +1355,8 @@ public class VolumePanel extends Handler {
|
||||
};
|
||||
|
||||
private final ZenModeController.Callback mZenCallback = new ZenModeController.Callback() {
|
||||
public void onZenChanged(int zen) {
|
||||
postZenModeChanged(zen);
|
||||
public void onZenAvailableChanged(boolean available) {
|
||||
obtainMessage(MSG_ZEN_MODE_AVAILABLE_CHANGED, available ? 1 : 0, 0).sendToTarget();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user