Merge "Volume: Hide zen options during setup." into lmp-dev
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/ZenModeController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/ZenModeController.java
index 2e97d18..6c4fb7a 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/ZenModeController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/ZenModeController.java
@@ -29,11 +29,13 @@
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) {}
}
}
\ No newline at end of file
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/ZenModeControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/ZenModeControllerImpl.java
index a3cdd41..9d3dec8 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/ZenModeControllerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/ZenModeControllerImpl.java
@@ -20,15 +20,18 @@
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 @@
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 @@
mNoMan = INotificationManager.Stub.asInterface(
ServiceManager.getService(Context.NOTIFICATION_SERVICE));
mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
+ mSetupObserver = new SetupObserver(handler);
+ mSetupObserver.register();
}
@Override
@@ -99,6 +105,11 @@
}
@Override
+ public boolean isZenAvailable() {
+ return mSetupObserver.isDeviceProvisioned() && mSetupObserver.isUserSetup();
+ }
+
+ @Override
public void requestConditions(boolean request) {
mRequesting = request;
try {
@@ -148,6 +159,7 @@
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 @@
}
}
+ 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 @@
}
}
};
+
+ 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());
+ }
+ }
+ }
}
diff --git a/packages/SystemUI/src/com/android/systemui/volume/VolumePanel.java b/packages/SystemUI/src/com/android/systemui/volume/VolumePanel.java
index 3a63a79..5233da2 100644
--- a/packages/SystemUI/src/com/android/systemui/volume/VolumePanel.java
+++ b/packages/SystemUI/src/com/android/systemui/volume/VolumePanel.java
@@ -107,7 +107,7 @@
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 @@
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 @@
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 @@
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 @@
active.group.setVisibility(View.VISIBLE);
updateSlider(active);
updateTimeoutDelay();
- setZenPanelVisible(isNotificationOrRing(mActiveStreamType));
+ updateZenPanelVisible();
}
}
@@ -776,14 +777,8 @@
}
}
- 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 @@
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 @@
};
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();
}
};