summaryrefslogtreecommitdiffstats
path: root/packages/SystemUI
diff options
context:
space:
mode:
authorJohn Spurlock <jspurlock@google.com>2015-02-13 14:50:49 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-02-13 14:50:50 +0000
commitb25334ca3c2c4f792254bf8e628788d0b7c4775a (patch)
tree882254ece704f001feb06029cf878e125b0cb024 /packages/SystemUI
parentd6d468ed9b63f7c79a7fa90451e526148b1d9dec (diff)
parentcdb57aeb0e2c83a887c86da0ca2a890df7f02f41 (diff)
downloadframeworks_base-b25334ca3c2c4f792254bf8e628788d0b7c4775a.zip
frameworks_base-b25334ca3c2c4f792254bf8e628788d0b7c4775a.tar.gz
frameworks_base-b25334ca3c2c4f792254bf8e628788d0b7c4775a.tar.bz2
Merge "Allow sysui-managed remote volume controllers."
Diffstat (limited to 'packages/SystemUI')
-rw-r--r--packages/SystemUI/res/values/ids.xml1
-rw-r--r--packages/SystemUI/res/values/strings.xml15
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/ServiceMonitor.java10
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/policy/ZenModeControllerImpl.java30
-rw-r--r--packages/SystemUI/src/com/android/systemui/volume/VolumeUI.java181
5 files changed, 180 insertions, 57 deletions
diff --git a/packages/SystemUI/res/values/ids.xml b/packages/SystemUI/res/values/ids.xml
index aa53a3e..3fc75d2 100644
--- a/packages/SystemUI/res/values/ids.xml
+++ b/packages/SystemUI/res/values/ids.xml
@@ -40,6 +40,7 @@
<item type="id" name="notification_power"/>
<item type="id" name="notification_screenshot"/>
<item type="id" name="notification_hidden"/>
+ <item type="id" name="notification_volumeui"/>
<!-- Whether the icon is from a notification for which targetSdk < L -->
<item type="id" name="icon_is_pre_L"/>
diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml
index 6afca8a..0420d35 100644
--- a/packages/SystemUI/res/values/strings.xml
+++ b/packages/SystemUI/res/values/strings.xml
@@ -932,4 +932,19 @@
<!-- Hide quick settings tile confirmation button -->
<string name="quick_settings_reset_confirmation_button">Hide</string>
+
+ <!-- VolumeUI activation dialog: warning message -->
+ <string name="volumeui_prompt_message"><xliff:g id="app_name" example="Volume Prototype 1">%1$s</xliff:g> wants to be the volume dialog.</string>
+
+ <!-- VolumeUI activation dialog: allow button label -->
+ <string name="volumeui_prompt_allow">Allow</string>
+
+ <!-- VolumeUI activation dialog: deny button label -->
+ <string name="volumeui_prompt_deny">Deny</string>
+
+ <!-- VolumeUI restoration notification: title -->
+ <string name="volumeui_notification_title"><xliff:g id="app_name" example="Volume Prototype 1">%1$s</xliff:g> is the volume dialog</string>
+
+ <!-- VolumeUI restoration notification: text -->
+ <string name="volumeui_notification_text">Touch to restore the original.</string>
</resources>
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ServiceMonitor.java b/packages/SystemUI/src/com/android/systemui/statusbar/ServiceMonitor.java
index aea9ec6..69a4932 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/ServiceMonitor.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/ServiceMonitor.java
@@ -279,4 +279,14 @@ public class ServiceMonitor {
}
return sb.append('}').toString();
}
+
+ public ComponentName getComponent() {
+ return getComponentNameFromSetting();
+ }
+
+ public void setComponent(ComponentName component) {
+ final String setting = component == null ? null : component.flattenToShortString();
+ Settings.Secure.putStringForUser(mContext.getContentResolver(),
+ mSettingKey, setting, UserHandle.USER_CURRENT);
+ }
}
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 dbdb578..bea0c86 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/ZenModeControllerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/ZenModeControllerImpl.java
@@ -17,7 +17,6 @@
package com.android.systemui.statusbar.policy;
import android.app.AlarmManager;
-import android.app.INotificationManager;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
@@ -28,8 +27,6 @@ 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;
@@ -53,7 +50,7 @@ public class ZenModeControllerImpl implements ZenModeController {
private final Context mContext;
private final GlobalSetting mModeSetting;
private final GlobalSetting mConfigSetting;
- private final INotificationManager mNoMan;
+ private final NotificationManager mNoMan;
private final LinkedHashMap<Uri, Condition> mConditions = new LinkedHashMap<Uri, Condition>();
private final AlarmManager mAlarmManager;
private final SetupObserver mSetupObserver;
@@ -78,8 +75,7 @@ public class ZenModeControllerImpl implements ZenModeController {
};
mModeSetting.setListening(true);
mConfigSetting.setListening(true);
- mNoMan = INotificationManager.Stub.asInterface(
- ServiceManager.getService(Context.NOTIFICATION_SERVICE));
+ mNoMan = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
mSetupObserver = new SetupObserver(handler);
mSetupObserver.register();
@@ -113,11 +109,7 @@ public class ZenModeControllerImpl implements ZenModeController {
@Override
public void requestConditions(boolean request) {
mRequesting = request;
- try {
- mNoMan.requestZenModeConditions(mListener, request ? Condition.FLAG_RELEVANT_NOW : 0);
- } catch (RemoteException e) {
- // noop
- }
+ mNoMan.requestZenModeConditions(mListener, request ? Condition.FLAG_RELEVANT_NOW : 0);
if (!mRequesting) {
mConditions.clear();
}
@@ -125,24 +117,12 @@ public class ZenModeControllerImpl implements ZenModeController {
@Override
public void setExitCondition(Condition exitCondition) {
- try {
- mNoMan.setZenModeCondition(exitCondition);
- } catch (RemoteException e) {
- // noop
- }
+ mNoMan.setZenModeCondition(exitCondition);
}
@Override
public Condition getExitCondition() {
- try {
- final ZenModeConfig config = mNoMan.getZenModeConfig();
- if (config != null) {
- return config.exitCondition;
- }
- } catch (RemoteException e) {
- // noop
- }
- return null;
+ return mNoMan.getZenModeCondition();
}
@Override
diff --git a/packages/SystemUI/src/com/android/systemui/volume/VolumeUI.java b/packages/SystemUI/src/com/android/systemui/volume/VolumeUI.java
index 7102c2a..8048a48 100644
--- a/packages/SystemUI/src/com/android/systemui/volume/VolumeUI.java
+++ b/packages/SystemUI/src/com/android/systemui/volume/VolumeUI.java
@@ -1,60 +1,73 @@
+/*
+ * Copyright (C) 2014 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.
+ */
+
package com.android.systemui.volume;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
import android.content.Context;
+import android.content.DialogInterface;
+import android.content.DialogInterface.OnClickListener;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.ApplicationInfo;
import android.content.res.Configuration;
-import android.database.ContentObserver;
import android.media.AudioManager;
import android.media.IRemoteVolumeController;
import android.media.IVolumeController;
import android.media.session.ISessionController;
import android.media.session.MediaController;
import android.media.session.MediaSessionManager;
-import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.RemoteException;
import android.provider.Settings;
+import android.text.TextUtils;
import android.util.Log;
import com.android.systemui.R;
import com.android.systemui.SystemUI;
import com.android.systemui.keyguard.KeyguardViewMediator;
+import com.android.systemui.statusbar.ServiceMonitor;
import com.android.systemui.statusbar.phone.PhoneStatusBar;
+import com.android.systemui.statusbar.phone.SystemUIDialog;
import com.android.systemui.statusbar.policy.ZenModeController;
import com.android.systemui.statusbar.policy.ZenModeControllerImpl;
import java.io.FileDescriptor;
import java.io.PrintWriter;
-/*
- * Copyright (C) 2014 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.
- */
-
public class VolumeUI extends SystemUI {
private static final String TAG = "VolumeUI";
- private static final String SETTING = "systemui_volume_controller"; // for testing
- private static final Uri SETTING_URI = Settings.Global.getUriFor(SETTING);
- private static final int DEFAULT = 1; // enabled by default
+ private static boolean LOGD = Log.isLoggable(TAG, Log.DEBUG);
private final Handler mHandler = new Handler();
+ private final Receiver mReceiver = new Receiver();
+ private final RestorationNotification mRestorationNotification = new RestorationNotification();
private boolean mEnabled;
private AudioManager mAudioManager;
+ private NotificationManager mNotificationManager;
private MediaSessionManager mMediaSessionManager;
private VolumeController mVolumeController;
private RemoteVolumeController mRemoteVolumeController;
+ private ServiceMonitor mVolumeControllerService;
private VolumePanel mPanel;
private int mDismissDelay;
@@ -64,14 +77,19 @@ public class VolumeUI extends SystemUI {
mEnabled = mContext.getResources().getBoolean(R.bool.enable_volume_ui);
if (!mEnabled) return;
mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
+ mNotificationManager =
+ (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
mMediaSessionManager = (MediaSessionManager) mContext
.getSystemService(Context.MEDIA_SESSION_SERVICE);
initPanel();
mVolumeController = new VolumeController();
mRemoteVolumeController = new RemoteVolumeController();
putComponent(VolumeComponent.class, mVolumeController);
- updateController();
- mContext.getContentResolver().registerContentObserver(SETTING_URI, false, mObserver);
+ mReceiver.start();
+ mVolumeControllerService = new ServiceMonitor(TAG, LOGD,
+ mContext, Settings.Secure.VOLUME_CONTROLLER_SERVICE_COMPONENT,
+ new ServiceMonitorCallbacks());
+ mVolumeControllerService.start();
}
@Override
@@ -85,18 +103,19 @@ public class VolumeUI extends SystemUI {
@Override
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
pw.print("mEnabled="); pw.println(mEnabled);
+ pw.print("mVolumeControllerService="); pw.println(mVolumeControllerService.getComponent());
if (mPanel != null) {
mPanel.dump(fd, pw, args);
}
}
- private void updateController() {
- if (Settings.Global.getInt(mContext.getContentResolver(), SETTING, DEFAULT) != 0) {
- Log.d(TAG, "Registering volume controller");
+ private void setVolumeController(boolean register) {
+ if (register) {
+ if (LOGD) Log.d(TAG, "Registering volume controller");
mAudioManager.setVolumeController(mVolumeController);
mMediaSessionManager.setRemoteVolumeController(mRemoteVolumeController);
} else {
- Log.d(TAG, "Unregistering volume controller");
+ if (LOGD) Log.d(TAG, "Unregistering volume controller");
mAudioManager.setVolumeController(null);
mMediaSessionManager.setRemoteVolumeController(null);
}
@@ -129,13 +148,32 @@ public class VolumeUI extends SystemUI {
});
}
- private final ContentObserver mObserver = new ContentObserver(mHandler) {
- public void onChange(boolean selfChange, Uri uri) {
- if (SETTING_URI.equals(uri)) {
- updateController();
+ private String getAppLabel(ComponentName component) {
+ final String pkg = component.getPackageName();
+ try {
+ final ApplicationInfo ai = mContext.getPackageManager().getApplicationInfo(pkg, 0);
+ final String rt = mContext.getPackageManager().getApplicationLabel(ai).toString();
+ if (!TextUtils.isEmpty(rt)) {
+ return rt;
}
+ } catch (Exception e) {
+ Log.w(TAG, "Error loading app label", e);
}
- };
+ return pkg;
+ }
+
+ private void showServiceActivationDialog(final ComponentName component) {
+ final SystemUIDialog d = new SystemUIDialog(mContext);
+ d.setMessage(mContext.getString(R.string.volumeui_prompt_message, getAppLabel(component)));
+ d.setPositiveButton(R.string.volumeui_prompt_allow, new OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ mVolumeControllerService.setComponent(component);
+ }
+ });
+ d.setNegativeButton(R.string.volumeui_prompt_deny, null);
+ d.show();
+ }
private final Runnable mStartZenSettings = new Runnable() {
@Override
@@ -213,4 +251,83 @@ public class VolumeUI extends SystemUI {
// than by remoteVolumeChanged.
}
}
+
+ private final class ServiceMonitorCallbacks implements ServiceMonitor.Callbacks {
+ @Override
+ public void onNoService() {
+ if (LOGD) Log.d(TAG, "onNoService");
+ setVolumeController(true);
+ mRestorationNotification.hide();
+ }
+
+ @Override
+ public long onServiceStartAttempt() {
+ if (LOGD) Log.d(TAG, "onServiceStartAttempt");
+ setVolumeController(false);
+ mVolumeController.dismissNow();
+ mRestorationNotification.show();
+ return 0;
+ }
+ }
+
+ private final class Receiver extends BroadcastReceiver {
+ private static final String ENABLE = "com.android.systemui.vui.ENABLE";
+ private static final String DISABLE = "com.android.systemui.vui.DISABLE";
+ private static final String EXTRA_COMPONENT = "component";
+
+ public void start() {
+ final IntentFilter filter = new IntentFilter();
+ filter.addAction(ENABLE);
+ filter.addAction(DISABLE);
+ mContext.registerReceiver(this, filter, null, mHandler);
+ }
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ final String action = intent.getAction();
+ final ComponentName component = intent.getParcelableExtra(EXTRA_COMPONENT);
+ final boolean current = component.equals(mVolumeControllerService.getComponent());
+ if (ENABLE.equals(action) && component != null) {
+ if (!current) {
+ showServiceActivationDialog(component);
+ }
+ }
+ if (DISABLE.equals(action) && component != null) {
+ if (current) {
+ mVolumeControllerService.setComponent(null);
+ }
+ }
+ }
+ }
+
+ private final class RestorationNotification {
+ public void hide() {
+ mNotificationManager.cancel(R.id.notification_volumeui);
+ }
+
+ public void show() {
+ final ComponentName component = mVolumeControllerService.getComponent();
+ if (component == null) {
+ Log.w(TAG, "Not showing restoration notification, component not active");
+ return;
+ }
+ final Intent intent = new Intent(Receiver.DISABLE)
+ .putExtra(Receiver.EXTRA_COMPONENT, component);
+ mNotificationManager.notify(R.id.notification_volumeui,
+ new Notification.Builder(mContext)
+ .setSmallIcon(R.drawable.ic_ringer_audible)
+ .setWhen(0)
+ .setShowWhen(false)
+ .setOngoing(true)
+ .setContentTitle(mContext.getString(
+ R.string.volumeui_notification_title, getAppLabel(component)))
+ .setContentText(mContext.getString(R.string.volumeui_notification_text))
+ .setContentIntent(PendingIntent.getBroadcast(mContext, 0, intent, 0))
+ .setPriority(Notification.PRIORITY_MIN)
+ .setVisibility(Notification.VISIBILITY_PUBLIC)
+ .setColor(mContext.getResources().getColor(
+ com.android.internal.R.color.system_notification_accent_color))
+ .build());
+ }
+ }
}