Use internal volume controller and status bar.

Remove code that let these components be replaced by external
processes.

Bug: 33006669
Bug: 34106436
Test: manual. reboot device, play music, change volume,
view notifications
Change-Id: I458f11537ab9db6f23735487513815553004613f
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 43590c7..568c160 100755
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -6394,13 +6394,6 @@
         public static final String ENABLED_NOTIFICATION_POLICY_ACCESS_PACKAGES =
                 "enabled_notification_policy_access_packages";
 
-        /** @hide */
-        public static final String BAR_SERVICE_COMPONENT = "bar_service_component";
-
-        /** @hide */
-        public static final String VOLUME_CONTROLLER_SERVICE_COMPONENT
-                = "volume_controller_service_component";
-
         /**
          * Defines whether managed profile ringtones should be synced from it's parent profile
          * <p>
diff --git a/media/java/android/media/AudioManagerInternal.java b/media/java/android/media/AudioManagerInternal.java
index ac59ace..b60dbd5 100644
--- a/media/java/android/media/AudioManagerInternal.java
+++ b/media/java/android/media/AudioManagerInternal.java
@@ -41,8 +41,6 @@
 
     public abstract void setRingerModeInternal(int ringerMode, String caller);
 
-    public abstract int getVolumeControllerUid();
-
     public abstract void updateRingerModeAffectedStreamsInternal();
 
     public interface RingerModeDelegate {
diff --git a/packages/SystemUI/res/values/ids.xml b/packages/SystemUI/res/values/ids.xml
index b4b873a..4a19dde 100644
--- a/packages/SystemUI/res/values/ids.xml
+++ b/packages/SystemUI/res/values/ids.xml
@@ -49,7 +49,11 @@
     <item type="id" name="scrim_target"/>
     <item type="id" name="scrim_alpha_start"/>
     <item type="id" name="scrim_alpha_end"/>
-    <item type="id" name="notification_volumeui"/>
+    <item type="id" name="notification_power"/>
+    <item type="id" name="notification_screenshot"/>
+    <item type="id" name="notification_hidden"/>
+    <item type="id" name="notification_temperature"/>
+    <item type="id" name="notification_plugin"/>
     <item type="id" name="transformation_start_x_tag"/>
     <item type="id" name="transformation_start_y_tag"/>
     <item type="id" name="transformation_start_scale_x_tag"/>
diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml
index d7033b2..87b2775 100644
--- a/packages/SystemUI/res/values/strings.xml
+++ b/packages/SystemUI/res/values/strings.xml
@@ -1125,21 +1125,6 @@
     <!-- 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">Tap to restore the original.</string>
-
     <!-- Toast shown when user unlocks screen and managed profile activity is in the foreground -->
     <string name="managed_profile_foreground_toast">You\'re using your work profile</string>
 
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ServiceMonitor.java b/packages/SystemUI/src/com/android/systemui/statusbar/ServiceMonitor.java
deleted file mode 100644
index db46dc6..0000000
--- a/packages/SystemUI/src/com/android/systemui/statusbar/ServiceMonitor.java
+++ /dev/null
@@ -1,305 +0,0 @@
-/*
- * Copyright (C) 2013 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.statusbar;
-
-import android.content.BroadcastReceiver;
-import android.content.ComponentName;
-import android.content.ContentResolver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.ServiceConnection;
-import android.content.pm.PackageManager;
-import android.database.ContentObserver;
-import android.net.Uri;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.IBinder;
-import android.os.Message;
-import android.os.RemoteException;
-import android.os.UserHandle;
-import android.provider.Settings;
-import android.util.Log;
-
-import java.util.Arrays;
-
-/**
- * Manages a persistent connection to a service component defined in a secure setting.
- *
- * <p>If a valid service component is specified in the secure setting, starts it up and keeps it
- * running; handling setting changes, package updates, component disabling, and unexpected
- * process termination.
- *
- * <p>Clients can listen for important events using the supplied {@link Callbacks}.
- */
-public class ServiceMonitor {
-    private static final int RECHECK_DELAY = 2000;
-    private static final int WAIT_FOR_STOP = 500;
-
-    public interface Callbacks {
-        /** The service does not exist or failed to bind */
-        void onNoService();
-        /** The service is about to start, this is a chance to perform cleanup and
-         * delay the start if necessary */
-        long onServiceStartAttempt();
-    }
-
-    // internal handler + messages used to serialize access to internal state
-    public static final int MSG_START_SERVICE = 1;
-    public static final int MSG_CONTINUE_START_SERVICE = 2;
-    public static final int MSG_STOP_SERVICE = 3;
-    public static final int MSG_PACKAGE_INTENT = 4;
-    public static final int MSG_CHECK_BOUND = 5;
-    public static final int MSG_SERVICE_DISCONNECTED = 6;
-
-    private final Handler mHandler = new Handler() {
-        public void handleMessage(Message msg) {
-            switch(msg.what) {
-                case MSG_START_SERVICE:
-                    startService();
-                    break;
-                case MSG_CONTINUE_START_SERVICE:
-                    continueStartService();
-                    break;
-                case MSG_STOP_SERVICE:
-                    stopService();
-                    break;
-                case MSG_PACKAGE_INTENT:
-                    packageIntent((Intent)msg.obj);
-                    break;
-                case MSG_CHECK_BOUND:
-                    checkBound();
-                    break;
-                case MSG_SERVICE_DISCONNECTED:
-                    serviceDisconnected((ComponentName)msg.obj);
-                    break;
-            }
-        }
-    };
-
-    private final ContentObserver mSettingObserver = new ContentObserver(mHandler) {
-        public void onChange(boolean selfChange) {
-            onChange(selfChange, null);
-        }
-
-        public void onChange(boolean selfChange, Uri uri) {
-            if (mDebug) Log.d(mTag, "onChange selfChange=" + selfChange + " uri=" + uri);
-            ComponentName cn = getComponentNameFromSetting();
-            if (cn == null && mServiceName == null || cn != null && cn.equals(mServiceName)) {
-                if (mDebug) Log.d(mTag, "skipping no-op restart");
-                return;
-            }
-            if (mBound) {
-                mHandler.sendEmptyMessage(MSG_STOP_SERVICE);
-            }
-            mHandler.sendEmptyMessageDelayed(MSG_START_SERVICE, WAIT_FOR_STOP);
-        }
-    };
-
-    private final class SC implements ServiceConnection, IBinder.DeathRecipient {
-        private ComponentName mName;
-        private IBinder mService;
-
-        public void onServiceConnected(ComponentName name, IBinder service) {
-            if (mDebug) Log.d(mTag, "onServiceConnected name=" + name + " service=" + service);
-            mName = name;
-            mService = service;
-            try {
-                service.linkToDeath(this, 0);
-            } catch (RemoteException e) {
-                Log.w(mTag, "Error linking to death", e);
-            }
-        }
-
-        public void onServiceDisconnected(ComponentName name) {
-            if (mDebug) Log.d(mTag, "onServiceDisconnected name=" + name);
-            boolean unlinked = mService.unlinkToDeath(this, 0);
-            if (mDebug) Log.d(mTag, "  unlinked=" + unlinked);
-            mHandler.sendMessage(mHandler.obtainMessage(MSG_SERVICE_DISCONNECTED, mName));
-        }
-
-        public void binderDied() {
-            if (mDebug) Log.d(mTag, "binderDied");
-            mHandler.sendMessage(mHandler.obtainMessage(MSG_SERVICE_DISCONNECTED, mName));
-        }
-    }
-
-    private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
-        public void onReceive(Context context, Intent intent) {
-            String pkg = intent.getData().getSchemeSpecificPart();
-            if (mServiceName != null && mServiceName.getPackageName().equals(pkg)) {
-                mHandler.sendMessage(mHandler.obtainMessage(MSG_PACKAGE_INTENT, intent));
-            }
-        }
-    };
-
-    private final String mTag;
-    private final boolean mDebug;
-
-    private final Context mContext;
-    private final String mSettingKey;
-    private final Callbacks mCallbacks;
-
-    private ComponentName mServiceName;
-    private SC mServiceConnection;
-    private boolean mBound;
-
-    public ServiceMonitor(String ownerTag, boolean debug,
-            Context context, String settingKey, Callbacks callbacks) {
-        mTag = ownerTag + ".ServiceMonitor";
-        mDebug = debug;
-        mContext = context;
-        mSettingKey = settingKey;
-        mCallbacks = callbacks;
-    }
-
-    public void start() {
-        // listen for setting changes
-        ContentResolver cr = mContext.getContentResolver();
-        cr.registerContentObserver(Settings.Secure.getUriFor(mSettingKey),
-                false /*notifyForDescendents*/, mSettingObserver, UserHandle.USER_ALL);
-
-        // listen for package/component changes
-        IntentFilter filter = new IntentFilter();
-        filter.addAction(Intent.ACTION_PACKAGE_ADDED);
-        filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
-        filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
-        filter.addDataScheme("package");
-        mContext.registerReceiver(mBroadcastReceiver, filter);
-
-        mHandler.sendEmptyMessage(MSG_START_SERVICE);
-    }
-
-    private ComponentName getComponentNameFromSetting() {
-        String cn = Settings.Secure.getStringForUser(mContext.getContentResolver(),
-                mSettingKey, UserHandle.USER_CURRENT);
-        return cn == null ? null : ComponentName.unflattenFromString(cn);
-    }
-
-    // everything below is called on the handler
-
-    private void packageIntent(Intent intent) {
-        if (mDebug) Log.d(mTag, "packageIntent intent=" + intent
-                + " extras=" + bundleToString(intent.getExtras()));
-        if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) {
-            mHandler.sendEmptyMessage(MSG_START_SERVICE);
-        } else if (Intent.ACTION_PACKAGE_CHANGED.equals(intent.getAction())
-                || Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) {
-            final PackageManager pm = mContext.getPackageManager();
-            final boolean serviceEnabled = isPackageAvailable()
-                    && pm.getApplicationEnabledSetting(mServiceName.getPackageName())
-                            != PackageManager.COMPONENT_ENABLED_STATE_DISABLED
-                    && pm.getComponentEnabledSetting(mServiceName)
-                            != PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
-            if (mBound && !serviceEnabled) {
-                stopService();
-                scheduleCheckBound();
-            } else if (!mBound && serviceEnabled) {
-                startService();
-            }
-        }
-    }
-
-    private void stopService() {
-        if (mDebug) Log.d(mTag, "stopService");
-        boolean stopped = mContext.stopService(new Intent().setComponent(mServiceName));
-        if (mDebug) Log.d(mTag, "  stopped=" + stopped);
-        mContext.unbindService(mServiceConnection);
-        mBound = false;
-    }
-
-    private void startService() {
-        mServiceName = getComponentNameFromSetting();
-        if (mDebug) Log.d(mTag, "startService mServiceName=" + mServiceName);
-        if (mServiceName == null) {
-            mBound = false;
-            mCallbacks.onNoService();
-        } else {
-            long delay = mCallbacks.onServiceStartAttempt();
-            mHandler.sendEmptyMessageDelayed(MSG_CONTINUE_START_SERVICE, delay);
-        }
-    }
-
-    private void continueStartService() {
-        if (mDebug) Log.d(mTag, "continueStartService");
-        Intent intent = new Intent().setComponent(mServiceName);
-        try {
-            mServiceConnection = new SC();
-            mBound = mContext.bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE);
-            if (mDebug) Log.d(mTag, "mBound: " + mBound);
-        } catch (Throwable t) {
-            Log.w(mTag, "Error binding to service: " + mServiceName, t);
-        }
-        if (!mBound) {
-            mCallbacks.onNoService();
-        }
-    }
-
-    private void serviceDisconnected(ComponentName serviceName) {
-        if (mDebug) Log.d(mTag, "serviceDisconnected serviceName=" + serviceName
-                + " mServiceName=" + mServiceName);
-        if (serviceName.equals(mServiceName)) {
-            mBound = false;
-            scheduleCheckBound();
-        }
-    }
-
-    private void checkBound() {
-        if (mDebug) Log.d(mTag, "checkBound mBound=" + mBound);
-        if (!mBound) {
-            startService();
-        }
-    }
-
-    private void scheduleCheckBound() {
-        mHandler.removeMessages(MSG_CHECK_BOUND);
-        mHandler.sendEmptyMessageDelayed(MSG_CHECK_BOUND, RECHECK_DELAY);
-    }
-
-    private static String bundleToString(Bundle bundle) {
-        if (bundle == null) return null;
-        StringBuilder sb = new StringBuilder("{");
-        for (String key : bundle.keySet()) {
-            if (sb.length() > 1) sb.append(',');
-            Object v = bundle.get(key);
-            v = (v instanceof String[]) ? Arrays.asList((String[]) v) : v;
-            sb.append(key).append('=').append(v);
-        }
-        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);
-    }
-
-    public boolean isPackageAvailable() {
-        final ComponentName component = getComponent();
-        if (component == null) return false;
-        try {
-            return mContext.getPackageManager().isPackageAvailable(component.getPackageName());
-        } catch (RuntimeException e) {
-            Log.w(mTag, "Error checking package availability", e);
-            return false;
-        }
-    }
-}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/SystemBars.java b/packages/SystemUI/src/com/android/systemui/statusbar/SystemBars.java
index 8819c60..275fd70 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/SystemBars.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/SystemBars.java
@@ -27,47 +27,21 @@
 import java.io.PrintWriter;
 
 /**
- * Ensure a single status bar service implementation is running at all times.
- *
- * <p>The implementation either comes from a service component running in a remote process (defined
- * using a secure setting), else falls back to using the in-process implementation according
- * to the product config.
+ * Ensure a single status bar service implementation is running at all times, using the in-process
+ * implementation according to the product config.
  */
-public class SystemBars extends SystemUI implements ServiceMonitor.Callbacks {
+public class SystemBars extends SystemUI {
     private static final String TAG = "SystemBars";
     private static final boolean DEBUG = false;
     private static final int WAIT_FOR_BARS_TO_DIE = 500;
 
-    // manages the implementation coming from the remote process
-    private ServiceMonitor mServiceMonitor;
-
     // in-process fallback implementation, per the product config
     private BaseStatusBar mStatusBar;
 
     @Override
     public void start() {
         if (DEBUG) Log.d(TAG, "start");
-        mServiceMonitor = new ServiceMonitor(TAG, DEBUG,
-                mContext, Settings.Secure.BAR_SERVICE_COMPONENT, this);
-        mServiceMonitor.start();  // will call onNoService if no remote service is found
-    }
-
-    @Override
-    public void onNoService() {
-        if (DEBUG) Log.d(TAG, "onNoService");
-        createStatusBarFromConfig();  // fallback to using an in-process implementation
-    }
-
-    @Override
-    public long onServiceStartAttempt() {
-        if (DEBUG) Log.d(TAG, "onServiceStartAttempt mStatusBar="+mStatusBar);
-        if (mStatusBar != null) {
-            // tear down the in-process version, we'll recreate it again if needed
-            mStatusBar.destroy();
-            mStatusBar = null;
-            return WAIT_FOR_BARS_TO_DIE;
-        }
-        return 0;
+        createStatusBarFromConfig();
     }
 
     @Override
diff --git a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogController.java b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogController.java
index 17dd8d6..0e5ff43 100644
--- a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogController.java
+++ b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogController.java
@@ -99,7 +99,6 @@
     private final Vibrator mVibrator;
     private final boolean mHasVibrator;
 
-    private boolean mEnabled;
     private boolean mDestroyed;
     private VolumePolicy mVolumePolicy;
     private boolean mShowDndTile = true;
@@ -198,7 +197,6 @@
 
     public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
         pw.println(VolumeDialogController.class.getSimpleName() + " state:");
-        pw.print("  mEnabled: "); pw.println(mEnabled);
         pw.print("  mDestroyed: "); pw.println(mDestroyed);
         pw.print("  mVolumePolicy: "); pw.println(mVolumePolicy);
         pw.print("  mState: "); pw.println(mState.toString(4));
@@ -749,8 +747,6 @@
 
 
     private final class SettingObserver extends ContentObserver {
-        private final Uri SERVICE_URI = Settings.Secure.getUriFor(
-                Settings.Secure.VOLUME_CONTROLLER_SERVICE_COMPONENT);
         private final Uri ZEN_MODE_URI =
                 Settings.Global.getUriFor(Settings.Global.ZEN_MODE);
         private final Uri ZEN_MODE_CONFIG_URI =
@@ -761,10 +757,8 @@
         }
 
         public void init() {
-            mContext.getContentResolver().registerContentObserver(SERVICE_URI, false, this);
             mContext.getContentResolver().registerContentObserver(ZEN_MODE_URI, false, this);
             mContext.getContentResolver().registerContentObserver(ZEN_MODE_CONFIG_URI, false, this);
-            onChange(true, SERVICE_URI);
         }
 
         public void destroy() {
@@ -774,17 +768,6 @@
         @Override
         public void onChange(boolean selfChange, Uri uri) {
             boolean changed = false;
-            if (SERVICE_URI.equals(uri)) {
-                final String setting = Settings.Secure.getString(mContext.getContentResolver(),
-                        Settings.Secure.VOLUME_CONTROLLER_SERVICE_COMPONENT);
-                final boolean enabled = setting != null && mComponent != null
-                        && mComponent.equals(ComponentName.unflattenFromString(setting));
-                if (enabled == mEnabled) return;
-                if (enabled) {
-                    register();
-                }
-                mEnabled = enabled;
-            }
             if (ZEN_MODE_URI.equals(uri)) {
                 changed = updateZenModeW();
             }
diff --git a/packages/SystemUI/src/com/android/systemui/volume/VolumeUI.java b/packages/SystemUI/src/com/android/systemui/volume/VolumeUI.java
index c820302..73d9ea7 100644
--- a/packages/SystemUI/src/com/android/systemui/volume/VolumeUI.java
+++ b/packages/SystemUI/src/com/android/systemui/volume/VolumeUI.java
@@ -16,31 +16,13 @@
 
 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.media.AudioManager;
-import android.media.session.MediaSessionManager;
 import android.os.Handler;
-import android.provider.Settings;
-import android.text.TextUtils;
 import android.util.Log;
 
-import com.android.systemui.Prefs;
 import com.android.systemui.R;
 import com.android.systemui.SystemUI;
 import com.android.systemui.qs.tiles.DndTile;
-import com.android.systemui.statusbar.ServiceMonitor;
-import com.android.systemui.statusbar.phone.SystemUIDialog;
 import com.android.systemui.statusbar.policy.ZenModeController;
 import com.android.systemui.statusbar.policy.ZenModeControllerImpl;
 
@@ -52,34 +34,18 @@
     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 ServiceMonitor mVolumeControllerService;
-
     private VolumeDialogComponent mVolumeComponent;
 
     @Override
     public void start() {
         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);
         final ZenModeController zenController = new ZenModeControllerImpl(mContext, mHandler);
         mVolumeComponent = new VolumeDialogComponent(this, mContext, null, zenController);
         putComponent(VolumeComponent.class, getVolumeComponent());
-        mReceiver.start();
-        mVolumeControllerService = new ServiceMonitor(TAG, LOGD,
-                mContext, Settings.Secure.VOLUME_CONTROLLER_SERVICE_COMPONENT,
-                new ServiceMonitorCallbacks());
-        mVolumeControllerService.start();
+        setDefaultVolumeController();
     }
 
     private VolumeComponent getVolumeComponent() {
@@ -97,154 +63,12 @@
     public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
         pw.print("mEnabled="); pw.println(mEnabled);
         if (!mEnabled) return;
-        pw.print("mVolumeControllerService="); pw.println(mVolumeControllerService.getComponent());
         getVolumeComponent().dump(fd, pw, args);
     }
 
-    private void setDefaultVolumeController(boolean register) {
-        if (register) {
-            DndTile.setVisible(mContext, true);
-            if (LOGD) Log.d(TAG, "Registering default volume controller");
-            getVolumeComponent().register();
-        } else {
-            if (LOGD) Log.d(TAG, "Unregistering default volume controller");
-            mAudioManager.setVolumeController(null);
-            mMediaSessionManager.setRemoteVolumeController(null);
-        }
-    }
-
-    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 class ServiceMonitorCallbacks implements ServiceMonitor.Callbacks {
-        @Override
-        public void onNoService() {
-            if (LOGD) Log.d(TAG, "onNoService");
-            setDefaultVolumeController(true);
-            mRestorationNotification.hide();
-            if (!mVolumeControllerService.isPackageAvailable()) {
-                mVolumeControllerService.setComponent(null);
-            }
-        }
-
-        @Override
-        public long onServiceStartAttempt() {
-            if (LOGD) Log.d(TAG, "onServiceStartAttempt");
-            // poke the setting to update the uid
-            mVolumeControllerService.setComponent(mVolumeControllerService.getComponent());
-            setDefaultVolumeController(false);
-            getVolumeComponent().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";
-
-        private static final String PREF = "com.android.systemui.PREF";
-        private static final String EXTRA_KEY = "key";
-        private static final String EXTRA_VALUE = "value";
-
-        public void start() {
-            final IntentFilter filter = new IntentFilter();
-            filter.addAction(ENABLE);
-            filter.addAction(DISABLE);
-            filter.addAction(PREF);
-            mContext.registerReceiver(this, filter, null, mHandler);
-        }
-
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            final String action = intent.getAction();
-            if (PREF.equals(action)) {
-                final String key = intent.getStringExtra(EXTRA_KEY);
-                if (key != null && intent.getExtras() != null) {
-                    final Object value = intent.getExtras().get(EXTRA_VALUE);
-                    if (value == null) {
-                        Prefs.remove(mContext, key);
-                    } else if (value instanceof Boolean) {
-                        Prefs.putBoolean(mContext, key, (Boolean) value);
-                    } else if (value instanceof Integer) {
-                        Prefs.putInt(mContext, key, (Integer) value);
-                    } else if (value instanceof Long) {
-                        Prefs.putLong(mContext, key, (Long) value);
-                    }
-                }
-                return;
-            }
-            final ComponentName component = intent.getParcelableExtra(EXTRA_COMPONENT);
-            final boolean current = component != null
-                    && 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);
-            Notification.Builder builder = new Notification.Builder(mContext)
-                    .setSmallIcon(R.drawable.ic_volume_media)
-                    .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,
-                            PendingIntent.FLAG_UPDATE_CURRENT))
-                    .setPriority(Notification.PRIORITY_MIN)
-                    .setVisibility(Notification.VISIBILITY_PUBLIC)
-                    .setColor(mContext.getColor(
-                            com.android.internal.R.color.system_notification_accent_color));
-            overrideNotificationAppName(mContext, builder);
-            mNotificationManager.notify(R.id.notification_volumeui,
-                    builder.build());
-        }
+    private void setDefaultVolumeController() {
+        DndTile.setVisible(mContext, true);
+        if (LOGD) Log.d(TAG, "Registering default volume controller");
+        getVolumeComponent().register();
     }
 }
diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java
index 2d42c33..0f3f9ce 100644
--- a/services/core/java/com/android/server/audio/AudioService.java
+++ b/services/core/java/com/android/server/audio/AudioService.java
@@ -191,7 +191,6 @@
 
     /** The controller for the volume UI. */
     private final VolumeController mVolumeController = new VolumeController();
-    private final ControllerService mControllerService = new ControllerService();
 
     // sendMsg() flags
     /** If the msg is already queued, replace it with this one. */
@@ -782,7 +781,6 @@
                 SAFE_VOLUME_CONFIGURE_TIMEOUT_MS);
 
         initA11yMonitoring(mContext);
-        mControllerService.init();
         onIndicateSystemReady();
     }
 
@@ -6065,7 +6063,6 @@
         pw.print("  mMcc="); pw.println(mMcc);
         pw.print("  mCameraSoundForced="); pw.println(mCameraSoundForced);
         pw.print("  mHasVibrator="); pw.println(mHasVibrator);
-        pw.print("  mControllerService="); pw.println(mControllerService);
         pw.print("  mVolumePolicy="); pw.println(mVolumePolicy);
 
         dumpAudioPolicies(pw);
@@ -6093,9 +6090,6 @@
     }
 
     private void enforceVolumeController(String action) {
-        if (mControllerService.mUid != 0 && Binder.getCallingUid() == mControllerService.mUid) {
-            return;
-        }
         mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR_SERVICE,
                 "Only SystemUI can " + action);
     }
@@ -6326,11 +6320,6 @@
         }
 
         @Override
-        public int getVolumeControllerUid() {
-            return mControllerService.mUid;
-        }
-
-        @Override
         public void updateRingerModeAffectedStreamsInternal() {
             synchronized (mSettingsLock) {
                 if (updateRingerModeAffectedStreams()) {
@@ -6591,42 +6580,4 @@
     private HashMap<IBinder, AudioPolicyProxy> mAudioPolicies =
             new HashMap<IBinder, AudioPolicyProxy>();
     private int mAudioPolicyCounter = 0; // always accessed synchronized on mAudioPolicies
-
-    private class ControllerService extends ContentObserver {
-        private int mUid;
-        private ComponentName mComponent;
-
-        public ControllerService() {
-            super(null);
-        }
-
-        @Override
-        public String toString() {
-            return String.format("{mUid=%d,mComponent=%s}", mUid, mComponent);
-        }
-
-        public void init() {
-            onChange(true);
-            mContentResolver.registerContentObserver(Settings.Secure.getUriFor(
-                    Settings.Secure.VOLUME_CONTROLLER_SERVICE_COMPONENT), false, this);
-        }
-
-        @Override
-        public void onChange(boolean selfChange) {
-            mUid = 0;
-            mComponent = null;
-            final String setting = Settings.Secure.getString(mContentResolver,
-                    Settings.Secure.VOLUME_CONTROLLER_SERVICE_COMPONENT);
-            if (setting == null) return;
-            try {
-                mComponent = ComponentName.unflattenFromString(setting);
-                if (mComponent == null) return;
-                mUid = mContext.getPackageManager()
-                        .getApplicationInfo(mComponent.getPackageName(), 0).uid;
-            } catch (Exception e) {
-                Log.w(TAG, "Error loading controller service", e);
-            }
-            if (DEBUG_VOL) Log.d(TAG, "Reloaded controller service: " + this);
-        }
-    }
 }
diff --git a/services/core/java/com/android/server/media/MediaSessionService.java b/services/core/java/com/android/server/media/MediaSessionService.java
index 4c58ffd..9b37f12 100644
--- a/services/core/java/com/android/server/media/MediaSessionService.java
+++ b/services/core/java/com/android/server/media/MediaSessionService.java
@@ -351,7 +351,7 @@
      */
     private void enforceMediaPermissions(ComponentName compName, int pid, int uid,
             int resolvedUserId) {
-        if (isCurrentVolumeController(uid)) return;
+        if (isCurrentVolumeController(uid, pid)) return;
         if (getContext()
                 .checkPermission(android.Manifest.permission.MEDIA_CONTENT_CONTROL, pid, uid)
                     != PackageManager.PERMISSION_GRANTED
@@ -361,20 +361,13 @@
         }
     }
 
-    private boolean isCurrentVolumeController(int uid) {
-        if (mAudioManagerInternal != null) {
-            final int vcuid = mAudioManagerInternal.getVolumeControllerUid();
-            if (vcuid > 0 && uid == vcuid) {
-                return true;
-            }
-        }
-        return false;
+    private boolean isCurrentVolumeController(int uid, int pid) {
+        return getContext().checkPermission(android.Manifest.permission.STATUS_BAR_SERVICE,
+                pid, uid) == PackageManager.PERMISSION_GRANTED;
     }
 
     private void enforceSystemUiPermission(String action, int pid, int uid) {
-        if (isCurrentVolumeController(uid)) return;
-        if (getContext().checkPermission(android.Manifest.permission.STATUS_BAR_SERVICE,
-                pid, uid) != PackageManager.PERMISSION_GRANTED) {
+        if (!isCurrentVolumeController(uid, pid)) {
             throw new SecurityException("Only system ui may " + action);
         }
     }
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index b08f800..4d8e26f 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -2021,13 +2021,13 @@
 
         @Override
         public ZenModeConfig getZenModeConfig() {
-            enforceSystemOrSystemUIOrVolume("INotificationManager.getZenModeConfig");
+            enforceSystemOrSystemUI("INotificationManager.getZenModeConfig");
             return mZenModeHelper.getConfig();
         }
 
         @Override
         public void setZenMode(int mode, Uri conditionId, String reason) throws RemoteException {
-            enforceSystemOrSystemUIOrVolume("INotificationManager.setZenMode");
+            enforceSystemOrSystemUI("INotificationManager.setZenMode");
             final long identity = Binder.clearCallingIdentity();
             try {
                 mZenModeHelper.setManualZenMode(mode, conditionId, null, reason);
@@ -2149,16 +2149,6 @@
             }
         }
 
-        private void enforceSystemOrSystemUIOrVolume(String message) {
-            if (mAudioManagerInternal != null) {
-                final int vcuid = mAudioManagerInternal.getVolumeControllerUid();
-                if (vcuid > 0 && Binder.getCallingUid() == vcuid) {
-                    return;
-                }
-            }
-            enforceSystemOrSystemUI(message);
-        }
-
         private void enforceSystemOrSystemUI(String message) {
             if (isCallerSystem()) return;
             getContext().enforceCallingPermission(android.Manifest.permission.STATUS_BAR_SERVICE,
@@ -2261,7 +2251,7 @@
 
         @Override
         public boolean isSystemConditionProviderEnabled(String path) {
-            enforceSystemOrSystemUIOrVolume("INotificationManager.isSystemConditionProviderEnabled");
+            enforceSystemOrSystemUI("INotificationManager.isSystemConditionProviderEnabled");
             return mConditionProviders.isSystemProviderEnabled(path);
         }