diff options
author | John Spurlock <jspurlock@google.com> | 2015-02-11 19:04:11 -0500 |
---|---|---|
committer | John Spurlock <jspurlock@google.com> | 2015-02-12 22:48:37 -0500 |
commit | cdb57aeb0e2c83a887c86da0ca2a890df7f02f41 (patch) | |
tree | cd58462862527b7eb432d1749e5752745f1b8889 /packages/SystemUI/src/com/android/systemui/volume | |
parent | ad680d46be19cbee16d42cbed4d2ed250648ac0b (diff) | |
download | frameworks_base-cdb57aeb0e2c83a887c86da0ca2a890df7f02f41.zip frameworks_base-cdb57aeb0e2c83a887c86da0ca2a890df7f02f41.tar.gz frameworks_base-cdb57aeb0e2c83a887c86da0ca2a890df7f02f41.tar.bz2 |
Allow sysui-managed remote volume controllers.
- Relax restriction on audio service calls that assume the volume
ui is systemui, allow calls from a blessed component app.
- Blessed component app service saved in secure settings.
- SystemUI mediates requests to replace the volume dialog, prompts
the user on activation.
- Show a low pri ongoing notification when the volume dialog is
being replaced, to allow user restoration at any time.
- Replace the controller management code in VolumeUI to use a
ServiceMonitor, backed by the new blessed app component setting.
- Add proper zen-related noman client wrappers, make avail to the
registered volume controller.
- Everything is still @hidden, no api impact.
Bug: 19260237
Change-Id: Ie1383f57659090318a7eda737fdad5b8f88737d4
Diffstat (limited to 'packages/SystemUI/src/com/android/systemui/volume')
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/volume/VolumeUI.java | 181 |
1 files changed, 149 insertions, 32 deletions
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()); + } + } } |