OSDN Git Service

Cleanup the status bar flow.
authorJason Monk <jmonk@google.com>
Tue, 5 Jan 2016 19:59:19 +0000 (14:59 -0500)
committerJason Monk <jmonk@google.com>
Fri, 8 Jan 2016 13:54:13 +0000 (08:54 -0500)
 - Don't round trip to the status bar manager to know the state
 - Manage the state of icons closer to where they are displayed
 - Move StatusBarIconList into SysUI because it isn't used elsewhere now

Change-Id: I99c4c290c18fc776914a43b1cde157f92bb36ac2

core/java/com/android/internal/statusbar/IStatusBar.aidl
core/java/com/android/internal/statusbar/IStatusBarService.aidl
core/java/com/android/internal/statusbar/StatusBarIconList.java [deleted file]
packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java
packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarIconController.java
packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarIconList.java [new file with mode: 0644]
packages/SystemUI/src/com/android/systemui/statusbar/tv/TvStatusBar.java
services/core/java/com/android/server/statusbar/StatusBarManagerService.java

index 4dd71e7..632285c 100644 (file)
@@ -24,8 +24,8 @@ import com.android.internal.statusbar.StatusBarIcon;
 /** @hide */
 oneway interface IStatusBar
 {
-    void setIcon(int index, in StatusBarIcon icon);
-    void removeIcon(int index);
+    void setIcon(String slot, in StatusBarIcon icon);
+    void removeIcon(String slot);
     void disable(int state1, int state2);
     void animateExpandNotificationsPanel();
     void animateExpandSettingsPanel(String subPanel);
index 0125d37..32de45c 100644 (file)
@@ -44,7 +44,8 @@ interface IStatusBarService
 
     // ---- Methods below are for use by the status bar policy services ----
     // You need the STATUS_BAR_SERVICE permission
-    void registerStatusBar(IStatusBar callbacks, out StatusBarIconList iconList,
+    void registerStatusBar(IStatusBar callbacks, out List<String> iconSlots,
+            out List<StatusBarIcon> iconList,
             out int[] switches, out List<IBinder> binders);
     void onPanelRevealed(boolean clearNotificationEffects, int numItems);
     void onPanelHidden();
diff --git a/core/java/com/android/internal/statusbar/StatusBarIconList.java b/core/java/com/android/internal/statusbar/StatusBarIconList.java
deleted file mode 100644 (file)
index 478d245..0000000
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * Copyright (C) 2007 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.internal.statusbar;
-
-import android.os.Parcel;
-import android.os.Parcelable;
-
-import java.io.PrintWriter;
-
-public class StatusBarIconList implements Parcelable {
-    private String[] mSlots;
-    private StatusBarIcon[] mIcons;
-
-    public StatusBarIconList() {
-    }
-
-    public StatusBarIconList(Parcel in) {
-        readFromParcel(in);
-    }
-    
-    public void readFromParcel(Parcel in) {
-        this.mSlots = in.readStringArray();
-        final int N = in.readInt();
-        if (N < 0) {
-            mIcons = null;
-        } else {
-            mIcons = new StatusBarIcon[N];
-            for (int i=0; i<N; i++) {
-                if (in.readInt() != 0) {
-                    mIcons[i] = new StatusBarIcon(in);
-                }
-            }
-        }
-    }
-
-    public void writeToParcel(Parcel out, int flags) {
-        out.writeStringArray(mSlots);
-        if (mIcons == null) {
-            out.writeInt(-1);
-        } else {
-            final int N = mIcons.length;
-            out.writeInt(N);
-            for (int i=0; i<N; i++) {
-                StatusBarIcon ic = mIcons[i];
-                if (ic == null) {
-                    out.writeInt(0);
-                } else {
-                    out.writeInt(1);
-                    ic.writeToParcel(out, flags);
-                }
-            }
-        }
-    }
-
-    public int describeContents() {
-        return 0;
-    }
-
-    /**
-     * Parcelable.Creator that instantiates StatusBarIconList objects
-     */
-    public static final Parcelable.Creator<StatusBarIconList> CREATOR
-            = new Parcelable.Creator<StatusBarIconList>()
-    {
-        public StatusBarIconList createFromParcel(Parcel parcel)
-        {
-            return new StatusBarIconList(parcel);
-        }
-
-        public StatusBarIconList[] newArray(int size)
-        {
-            return new StatusBarIconList[size];
-        }
-    };
-
-    public void defineSlots(String[] slots) {
-        final int N = slots.length;
-        String[] s = mSlots = new String[N];
-        for (int i=0; i<N; i++) {
-            s[i] = slots[i];
-        }
-        mIcons = new StatusBarIcon[N];
-    }
-
-    public int getSlotIndex(String slot) {
-        final int N = mSlots.length;
-        for (int i=0; i<N; i++) {
-            if (slot.equals(mSlots[i])) {
-                return i;
-            }
-        }
-        return -1;
-    }
-
-    public int size() {
-        return mSlots.length;
-    }
-
-    public void setIcon(int index, StatusBarIcon icon) {
-        mIcons[index] = icon.clone();
-    }
-
-    public void removeIcon(int index) {
-        mIcons[index] = null;
-    }
-
-    public String getSlot(int index) {
-        return mSlots[index];
-    }
-
-    public StatusBarIcon getIcon(int index) {
-        return mIcons[index];
-    }
-
-    public int getViewIndex(int index) {
-        int count = 0;
-        for (int i=0; i<index; i++) {
-            if (mIcons[i] != null) {
-                count++;
-            }
-        }
-        return count;
-    }
-
-    public void copyFrom(StatusBarIconList that) {
-        if (that.mSlots == null) {
-            this.mSlots = null;
-            this.mIcons = null;
-        } else {
-            final int N = that.mSlots.length;
-            this.mSlots = new String[N];
-            this.mIcons = new StatusBarIcon[N];
-            for (int i=0; i<N; i++) {
-                this.mSlots[i] = that.mSlots[i];
-                this.mIcons[i] = that.mIcons[i] != null ? that.mIcons[i].clone() : null;
-            }
-        }
-    }
-
-    public void dump(PrintWriter pw) {
-        final int N = mSlots.length;
-        pw.println("Icon list:");
-        for (int i=0; i<N; i++) {
-            pw.printf("  %2d: (%s) %s\n", i, mSlots[i], mIcons[i]);
-        }
-    }
-}
index fdfce6c..6efb774 100644 (file)
@@ -21,7 +21,6 @@ import android.animation.AnimatorListenerAdapter;
 import android.animation.TimeInterpolator;
 import android.app.ActivityManager;
 import android.app.ActivityManagerNative;
-import android.app.INotificationManager;
 import android.app.Notification;
 import android.app.NotificationManager;
 import android.app.PendingIntent;
@@ -82,11 +81,9 @@ import android.widget.ImageView;
 import android.widget.RemoteViews;
 import android.widget.TextView;
 import android.widget.Toast;
-
 import com.android.internal.logging.MetricsLogger;
 import com.android.internal.statusbar.IStatusBarService;
 import com.android.internal.statusbar.StatusBarIcon;
-import com.android.internal.statusbar.StatusBarIconList;
 import com.android.internal.util.NotificationColorUtil;
 import com.android.internal.widget.LockPatternUtils;
 import com.android.keyguard.KeyguardUpdateMonitor;
@@ -647,13 +644,14 @@ public abstract class BaseStatusBar extends SystemUI implements
                 android.R.interpolator.fast_out_linear_in);
 
         // Connect in to the status bar manager service
-        StatusBarIconList iconList = new StatusBarIconList();
-        mCommandQueue = new CommandQueue(this, iconList);
+        mCommandQueue = new CommandQueue(this);
 
         int[] switches = new int[8];
         ArrayList<IBinder> binders = new ArrayList<IBinder>();
+        ArrayList<String> iconSlots = new ArrayList<>();
+        ArrayList<StatusBarIcon> icons = new ArrayList<>();
         try {
-            mBarService.registerStatusBar(mCommandQueue, iconList, switches, binders);
+            mBarService.registerStatusBar(mCommandQueue, iconSlots, icons, switches, binders);
         } catch (RemoteException ex) {
             // If the system process isn't there we're doomed anyway.
         }
@@ -668,14 +666,10 @@ public abstract class BaseStatusBar extends SystemUI implements
         setImeWindowStatus(binders.get(0), switches[3], switches[4], switches[5] != 0);
 
         // Set up the initial icon state
-        int N = iconList.size();
+        int N = iconSlots.size();
         int viewIndex = 0;
-        for (int i=0; i<N; i++) {
-            StatusBarIcon icon = iconList.getIcon(i);
-            if (icon != null) {
-                addIcon(iconList.getSlot(i), i, viewIndex, icon);
-                viewIndex++;
-            }
+        for (int i=0; i < N; i++) {
+            setIcon(iconSlots.get(i), icons.get(i));
         }
 
         // Set up the initial notification state.
@@ -691,7 +685,7 @@ public abstract class BaseStatusBar extends SystemUI implements
         if (DEBUG) {
             Log.d(TAG, String.format(
                     "init: icons=%d disabled=0x%08x lights=0x%08x menu=0x%08x imeButton=0x%08x",
-                   iconList.size(),
+                   icons.size(),
                    switches[0],
                    switches[1],
                    switches[2],
index 5a2758d..cc26223 100644 (file)
@@ -21,10 +21,8 @@ import android.os.Handler;
 import android.os.IBinder;
 import android.os.Message;
 import android.util.Pair;
-
 import com.android.internal.statusbar.IStatusBar;
 import com.android.internal.statusbar.StatusBarIcon;
-import com.android.internal.statusbar.StatusBarIconList;
 
 /**
  * This class takes the functions from IStatusBar that come in on
@@ -76,7 +74,7 @@ public class CommandQueue extends IStatusBar.Stub {
 
     private static final String SHOW_IME_SWITCHER_KEY = "showImeSwitcherKey";
 
-    private StatusBarIconList mList;
+    private final Object mLock = new Object();
     private Callbacks mCallbacks;
     private Handler mHandler = new H();
 
@@ -84,10 +82,8 @@ public class CommandQueue extends IStatusBar.Stub {
      * These methods are called back on the main thread.
      */
     public interface Callbacks {
-        public void addIcon(String slot, int index, int viewIndex, StatusBarIcon icon);
-        public void updateIcon(String slot, int index, int viewIndex,
-                StatusBarIcon old, StatusBarIcon icon);
-        public void removeIcon(String slot, int index, int viewIndex);
+        public void setIcon(String slot, StatusBarIcon icon);
+        public void removeIcon(String slot);
         public void disable(int state1, int state2, boolean animate);
         public void animateExpandNotificationsPanel();
         public void animateCollapsePanels(int flags);
@@ -115,57 +111,55 @@ public class CommandQueue extends IStatusBar.Stub {
         public void onCameraLaunchGestureDetected(int source);
     }
 
-    public CommandQueue(Callbacks callbacks, StatusBarIconList list) {
+    public CommandQueue(Callbacks callbacks) {
         mCallbacks = callbacks;
-        mList = list;
     }
 
-    public void setIcon(int index, StatusBarIcon icon) {
-        synchronized (mList) {
-            int what = MSG_ICON | index;
-            mHandler.removeMessages(what);
-            mHandler.obtainMessage(what, OP_SET_ICON, 0, icon.clone()).sendToTarget();
+    public void setIcon(String slot, StatusBarIcon icon) {
+        synchronized (mLock) {
+            // don't coalesce these
+            mHandler.obtainMessage(MSG_ICON, OP_SET_ICON, 0,
+                    new Pair<String, StatusBarIcon>(slot, icon)).sendToTarget();
         }
     }
 
-    public void removeIcon(int index) {
-        synchronized (mList) {
-            int what = MSG_ICON | index;
-            mHandler.removeMessages(what);
-            mHandler.obtainMessage(what, OP_REMOVE_ICON, 0, null).sendToTarget();
+    public void removeIcon(String slot) {
+        synchronized (mLock) {
+            // don't coalesce these
+            mHandler.obtainMessage(MSG_ICON, OP_REMOVE_ICON, 0, slot).sendToTarget();
         }
     }
 
     public void disable(int state1, int state2) {
-        synchronized (mList) {
+        synchronized (mLock) {
             mHandler.removeMessages(MSG_DISABLE);
             mHandler.obtainMessage(MSG_DISABLE, state1, state2, null).sendToTarget();
         }
     }
 
     public void animateExpandNotificationsPanel() {
-        synchronized (mList) {
+        synchronized (mLock) {
             mHandler.removeMessages(MSG_EXPAND_NOTIFICATIONS);
             mHandler.sendEmptyMessage(MSG_EXPAND_NOTIFICATIONS);
         }
     }
 
     public void animateCollapsePanels() {
-        synchronized (mList) {
+        synchronized (mLock) {
             mHandler.removeMessages(MSG_COLLAPSE_PANELS);
             mHandler.sendEmptyMessage(MSG_COLLAPSE_PANELS);
         }
     }
 
     public void animateExpandSettingsPanel(String subPanel) {
-        synchronized (mList) {
+        synchronized (mLock) {
             mHandler.removeMessages(MSG_EXPAND_SETTINGS);
             mHandler.obtainMessage(MSG_EXPAND_SETTINGS, subPanel).sendToTarget();
         }
     }
 
     public void setSystemUiVisibility(int vis, int mask) {
-        synchronized (mList) {
+        synchronized (mLock) {
             // Don't coalesce these, since it might have one time flags set such as
             // STATUS_BAR_UNHIDE which might get lost.
             mHandler.obtainMessage(MSG_SET_SYSTEMUI_VISIBILITY, vis, mask, null).sendToTarget();
@@ -173,7 +167,7 @@ public class CommandQueue extends IStatusBar.Stub {
     }
 
     public void topAppWindowChanged(boolean menuVisible) {
-        synchronized (mList) {
+        synchronized (mLock) {
             mHandler.removeMessages(MSG_TOP_APP_WINDOW_CHANGED);
             mHandler.obtainMessage(MSG_TOP_APP_WINDOW_CHANGED, menuVisible ? 1 : 0, 0,
                     null).sendToTarget();
@@ -182,7 +176,7 @@ public class CommandQueue extends IStatusBar.Stub {
 
     public void setImeWindowStatus(IBinder token, int vis, int backDisposition,
             boolean showImeSwitcher) {
-        synchronized (mList) {
+        synchronized (mLock) {
             mHandler.removeMessages(MSG_SHOW_IME_BUTTON);
             Message m = mHandler.obtainMessage(MSG_SHOW_IME_BUTTON, vis, backDisposition, token);
             m.getData().putBoolean(SHOW_IME_SWITCHER_KEY, showImeSwitcher);
@@ -191,7 +185,7 @@ public class CommandQueue extends IStatusBar.Stub {
     }
 
     public void showRecentApps(boolean triggeredFromAltTab) {
-        synchronized (mList) {
+        synchronized (mLock) {
             mHandler.removeMessages(MSG_SHOW_RECENT_APPS);
             mHandler.obtainMessage(MSG_SHOW_RECENT_APPS,
                     triggeredFromAltTab ? 1 : 0, 0, null).sendToTarget();
@@ -199,7 +193,7 @@ public class CommandQueue extends IStatusBar.Stub {
     }
 
     public void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHomeKey) {
-        synchronized (mList) {
+        synchronized (mLock) {
             mHandler.removeMessages(MSG_HIDE_RECENT_APPS);
             mHandler.obtainMessage(MSG_HIDE_RECENT_APPS,
                     triggeredFromAltTab ? 1 : 0, triggeredFromHomeKey ? 1 : 0,
@@ -208,21 +202,21 @@ public class CommandQueue extends IStatusBar.Stub {
     }
 
     public void toggleRecentApps() {
-        synchronized (mList) {
+        synchronized (mLock) {
             mHandler.removeMessages(MSG_TOGGLE_RECENT_APPS);
             mHandler.obtainMessage(MSG_TOGGLE_RECENT_APPS, 0, 0, null).sendToTarget();
         }
     }
 
     public void preloadRecentApps() {
-        synchronized (mList) {
+        synchronized (mLock) {
             mHandler.removeMessages(MSG_PRELOAD_RECENT_APPS);
             mHandler.obtainMessage(MSG_PRELOAD_RECENT_APPS, 0, 0, null).sendToTarget();
         }
     }
 
     public void cancelPreloadRecentApps() {
-        synchronized (mList) {
+        synchronized (mLock) {
             mHandler.removeMessages(MSG_CANCEL_PRELOAD_RECENT_APPS);
             mHandler.obtainMessage(MSG_CANCEL_PRELOAD_RECENT_APPS, 0, 0, null).sendToTarget();
         }
@@ -230,61 +224,61 @@ public class CommandQueue extends IStatusBar.Stub {
 
     @Override
     public void toggleKeyboardShortcutsMenu() {
-        synchronized (mList) {
+        synchronized (mLock) {
             mHandler.removeMessages(MSG_TOGGLE_KEYBOARD_SHORTCUTS);
             mHandler.obtainMessage(MSG_TOGGLE_KEYBOARD_SHORTCUTS).sendToTarget();
         }
     }
 
     public void setWindowState(int window, int state) {
-        synchronized (mList) {
+        synchronized (mLock) {
             // don't coalesce these
             mHandler.obtainMessage(MSG_SET_WINDOW_STATE, window, state, null).sendToTarget();
         }
     }
 
     public void buzzBeepBlinked() {
-        synchronized (mList) {
+        synchronized (mLock) {
             mHandler.removeMessages(MSG_BUZZ_BEEP_BLINKED);
             mHandler.sendEmptyMessage(MSG_BUZZ_BEEP_BLINKED);
         }
     }
 
     public void notificationLightOff() {
-        synchronized (mList) {
+        synchronized (mLock) {
             mHandler.sendEmptyMessage(MSG_NOTIFICATION_LIGHT_OFF);
         }
     }
 
     public void notificationLightPulse(int argb, int onMillis, int offMillis) {
-        synchronized (mList) {
+        synchronized (mLock) {
             mHandler.obtainMessage(MSG_NOTIFICATION_LIGHT_PULSE, onMillis, offMillis, argb)
                     .sendToTarget();
         }
     }
 
     public void showScreenPinningRequest() {
-        synchronized (mList) {
+        synchronized (mLock) {
             mHandler.sendEmptyMessage(MSG_SHOW_SCREEN_PIN_REQUEST);
         }
     }
 
     public void appTransitionPending() {
-        synchronized (mList) {
+        synchronized (mLock) {
             mHandler.removeMessages(MSG_APP_TRANSITION_PENDING);
             mHandler.sendEmptyMessage(MSG_APP_TRANSITION_PENDING);
         }
     }
 
     public void appTransitionCancelled() {
-        synchronized (mList) {
+        synchronized (mLock) {
             mHandler.removeMessages(MSG_APP_TRANSITION_PENDING);
             mHandler.sendEmptyMessage(MSG_APP_TRANSITION_PENDING);
         }
     }
 
     public void appTransitionStarting(long startTime, long duration) {
-        synchronized (mList) {
+        synchronized (mLock) {
             mHandler.removeMessages(MSG_APP_TRANSITION_STARTING);
             mHandler.obtainMessage(MSG_APP_TRANSITION_STARTING, Pair.create(startTime, duration))
                     .sendToTarget();
@@ -292,14 +286,14 @@ public class CommandQueue extends IStatusBar.Stub {
     }
 
     public void showAssistDisclosure() {
-        synchronized (mList) {
+        synchronized (mLock) {
             mHandler.removeMessages(MSG_ASSIST_DISCLOSURE);
             mHandler.obtainMessage(MSG_ASSIST_DISCLOSURE).sendToTarget();
         }
     }
 
     public void startAssist(Bundle args) {
-        synchronized (mList) {
+        synchronized (mLock) {
             mHandler.removeMessages(MSG_START_ASSIST);
             mHandler.obtainMessage(MSG_START_ASSIST, args).sendToTarget();
         }
@@ -307,7 +301,7 @@ public class CommandQueue extends IStatusBar.Stub {
 
     @Override
     public void onCameraLaunchGestureDetected(int source) {
-        synchronized (mList) {
+        synchronized (mLock) {
             mHandler.removeMessages(MSG_CAMERA_LAUNCH_GESTURE);
             mHandler.obtainMessage(MSG_CAMERA_LAUNCH_GESTURE, source, 0).sendToTarget();
         }
@@ -318,27 +312,14 @@ public class CommandQueue extends IStatusBar.Stub {
             final int what = msg.what & MSG_MASK;
             switch (what) {
                 case MSG_ICON: {
-                    final int index = msg.what & INDEX_MASK;
-                    final int viewIndex = mList.getViewIndex(index);
                     switch (msg.arg1) {
                         case OP_SET_ICON: {
-                            StatusBarIcon icon = (StatusBarIcon)msg.obj;
-                            StatusBarIcon old = mList.getIcon(index);
-                            if (old == null) {
-                                mList.setIcon(index, icon);
-                                mCallbacks.addIcon(mList.getSlot(index), index, viewIndex, icon);
-                            } else {
-                                mList.setIcon(index, icon);
-                                mCallbacks.updateIcon(mList.getSlot(index), index, viewIndex,
-                                        old, icon);
-                            }
+                            Pair<String, StatusBarIcon> p = (Pair<String, StatusBarIcon>) msg.obj;
+                            mCallbacks.setIcon(p.first, p.second);
                             break;
                         }
                         case OP_REMOVE_ICON:
-                            if (mList.getIcon(index) != null) {
-                                mList.removeIcon(index);
-                                mCallbacks.removeIcon(mList.getSlot(index), index, viewIndex);
-                            }
+                            mCallbacks.removeIcon((String) msg.obj);
                             break;
                     }
                     break;
index d688250..cc380d8 100644 (file)
@@ -83,7 +83,6 @@ import android.view.MotionEvent;
 import android.view.ThreadedRenderer;
 import android.view.VelocityTracker;
 import android.view.View;
-import android.view.ViewGroup;
 import android.view.ViewGroup.LayoutParams;
 import android.view.ViewStub;
 import android.view.WindowManager;
@@ -95,7 +94,6 @@ import android.view.animation.LinearInterpolator;
 import android.view.animation.PathInterpolator;
 import android.widget.ImageView;
 import android.widget.TextView;
-
 import com.android.internal.logging.MetricsLogger;
 import com.android.internal.statusbar.NotificationVisibility;
 import com.android.internal.statusbar.StatusBarIcon;
@@ -152,7 +150,6 @@ import com.android.systemui.statusbar.policy.LocationControllerImpl;
 import com.android.systemui.statusbar.policy.NetworkControllerImpl;
 import com.android.systemui.statusbar.policy.NextAlarmController;
 import com.android.systemui.statusbar.policy.PreviewInflater;
-import com.android.systemui.statusbar.policy.RemoteInputView;
 import com.android.systemui.statusbar.policy.RotationLockControllerImpl;
 import com.android.systemui.statusbar.policy.SecurityControllerImpl;
 import com.android.systemui.statusbar.policy.UserInfoController;
@@ -637,8 +634,8 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
         addNavigationBar();
 
         // Lastly, call to the icon policy to install/update all the icons.
-        mIconPolicy = new PhoneStatusBarPolicy(mContext, mCastController, mHotspotController,
-                mUserInfoController, mBluetoothController);
+        mIconPolicy = new PhoneStatusBarPolicy(mContext, mIconController, mCastController,
+                mHotspotController, mUserInfoController, mBluetoothController);
         mIconPolicy.setCurrentUserSetup(mUserSetup);
         mSettingsObserver.onChange(false); // set up
 
@@ -1239,17 +1236,14 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
         return lp;
     }
 
-    public void addIcon(String slot, int index, int viewIndex, StatusBarIcon icon) {
-        mIconController.addSystemIcon(slot, index, viewIndex, icon);
-    }
-
-    public void updateIcon(String slot, int index, int viewIndex,
-            StatusBarIcon old, StatusBarIcon icon) {
-        mIconController.updateSystemIcon(slot, index, viewIndex, old, icon);
+    @Override
+    public void setIcon(String slot, StatusBarIcon icon) {
+        mIconController.setIcon(slot, icon);
     }
 
-    public void removeIcon(String slot, int index, int viewIndex) {
-        mIconController.removeSystemIcon(slot, index, viewIndex);
+    @Override
+    public void removeIcon(String slot) {
+        mIconController.removeIcon(slot);
     }
 
     public UserHandle getCurrentUserHandle() {
index b89cd22..59d831c 100644 (file)
@@ -20,7 +20,6 @@ import android.app.ActivityManager;
 import android.app.ActivityManagerNative;
 import android.app.AlarmManager;
 import android.app.AlarmManager.AlarmClockInfo;
-import android.app.StatusBarManager;
 import android.app.SynchronousUserSwitchObserver;
 import android.content.BroadcastReceiver;
 import android.content.Context;
@@ -35,7 +34,6 @@ import android.os.UserManager;
 import android.provider.Settings.Global;
 import android.telecom.TelecomManager;
 import android.util.Log;
-
 import com.android.internal.telephony.IccCardConstants;
 import com.android.internal.telephony.TelephonyIntents;
 import com.android.systemui.R;
@@ -66,13 +64,13 @@ public class PhoneStatusBarPolicy implements Callback {
     private static final String SLOT_MANAGED_PROFILE = "managed_profile";
 
     private final Context mContext;
-    private final StatusBarManager mService;
     private final Handler mHandler = new Handler();
     private final CastController mCast;
     private final HotspotController mHotspot;
     private final AlarmManager mAlarmManager;
     private final UserInfoController mUserInfoController;
     private final UserManager mUserManager;
+    private final StatusBarIconController mIconController;
 
     // Assume it's all good unless we hear otherwise.  We don't always seem
     // to get broadcasts that it *is* there.
@@ -97,18 +95,14 @@ public class PhoneStatusBarPolicy implements Callback {
             String action = intent.getAction();
             if (action.equals(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED)) {
                 updateAlarm();
-            }
-            else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION) ||
+            } else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION) ||
                     action.equals(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION)) {
                 updateVolumeZen();
-            }
-            else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
+            } else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
                 updateSimState(intent);
-            }
-            else if (action.equals(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED)) {
+            } else if (action.equals(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED)) {
                 updateTTY(intent);
-            }
-            else if (action.equals(Intent.ACTION_MANAGED_PROFILE_AVAILABILITY_CHANGED)) {
+            } else if (action.equals(Intent.ACTION_MANAGED_PROFILE_AVAILABILITY_CHANGED)) {
                 updateQuietState();
                 updateManagedProfile();
             }
@@ -119,18 +113,19 @@ public class PhoneStatusBarPolicy implements Callback {
         @Override
         public void run() {
             if (DEBUG) Log.v(TAG, "updateCast: hiding icon NOW");
-            mService.setIconVisibility(SLOT_CAST, false);
+            mIconController.setIconVisibility(SLOT_CAST, false);
         }
     };
 
-    public PhoneStatusBarPolicy(Context context, CastController cast, HotspotController hotspot,
-            UserInfoController userInfoController, BluetoothController bluetooth) {
+    public PhoneStatusBarPolicy(Context context, StatusBarIconController iconController,
+            CastController cast, HotspotController hotspot, UserInfoController userInfoController,
+            BluetoothController bluetooth) {
         mContext = context;
+        mIconController = iconController;
         mCast = cast;
         mHotspot = hotspot;
         mBluetooth = bluetooth;
         mBluetooth.addStateChangedCallback(this);
-        mService = (StatusBarManager) context.getSystemService(Context.STATUS_BAR_SERVICE);
         mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
         mUserInfoController = userInfoController;
         mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
@@ -153,40 +148,40 @@ public class PhoneStatusBarPolicy implements Callback {
         }
 
         // TTY status
-        mService.setIcon(SLOT_TTY,  R.drawable.stat_sys_tty_mode, 0, null);
-        mService.setIconVisibility(SLOT_TTY, false);
+        mIconController.setIcon(SLOT_TTY,  R.drawable.stat_sys_tty_mode, null);
+        mIconController.setIconVisibility(SLOT_TTY, false);
 
         // bluetooth status
         updateBluetooth();
 
         // Alarm clock
-        mService.setIcon(SLOT_ALARM_CLOCK, R.drawable.stat_sys_alarm, 0, null);
-        mService.setIconVisibility(SLOT_ALARM_CLOCK, false);
+        mIconController.setIcon(SLOT_ALARM_CLOCK, R.drawable.stat_sys_alarm, null);
+        mIconController.setIconVisibility(SLOT_ALARM_CLOCK, false);
 
         // zen
-        mService.setIcon(SLOT_ZEN, R.drawable.stat_sys_zen_important, 0, null);
-        mService.setIconVisibility(SLOT_ZEN, false);
+        mIconController.setIcon(SLOT_ZEN, R.drawable.stat_sys_zen_important, null);
+        mIconController.setIconVisibility(SLOT_ZEN, false);
 
         // volume
-        mService.setIcon(SLOT_VOLUME, R.drawable.stat_sys_ringer_vibrate, 0, null);
-        mService.setIconVisibility(SLOT_VOLUME, false);
+        mIconController.setIcon(SLOT_VOLUME, R.drawable.stat_sys_ringer_vibrate, null);
+        mIconController.setIconVisibility(SLOT_VOLUME, false);
         updateVolumeZen();
 
         // cast
-        mService.setIcon(SLOT_CAST, R.drawable.stat_sys_cast, 0, null);
-        mService.setIconVisibility(SLOT_CAST, false);
+        mIconController.setIcon(SLOT_CAST, R.drawable.stat_sys_cast, null);
+        mIconController.setIconVisibility(SLOT_CAST, false);
         mCast.addCallback(mCastCallback);
 
         // hotspot
-        mService.setIcon(SLOT_HOTSPOT, R.drawable.stat_sys_hotspot, 0,
+        mIconController.setIcon(SLOT_HOTSPOT, R.drawable.stat_sys_hotspot,
                 mContext.getString(R.string.accessibility_status_bar_hotspot));
-        mService.setIconVisibility(SLOT_HOTSPOT, mHotspot.isHotspotEnabled());
+        mIconController.setIconVisibility(SLOT_HOTSPOT, mHotspot.isHotspotEnabled());
         mHotspot.addCallback(mHotspotCallback);
 
         // managed profile
-        mService.setIcon(SLOT_MANAGED_PROFILE, R.drawable.stat_sys_managed_profile_status, 0,
+        mIconController.setIcon(SLOT_MANAGED_PROFILE, R.drawable.stat_sys_managed_profile_status,
                 mContext.getString(R.string.accessibility_managed_profile));
-        mService.setIconVisibility(SLOT_MANAGED_PROFILE, mManagedProfileIconVisible);
+        mIconController.setIconVisibility(SLOT_MANAGED_PROFILE, mManagedProfileIconVisible);
     }
 
     public void setZenMode(int zen) {
@@ -198,32 +193,27 @@ public class PhoneStatusBarPolicy implements Callback {
         final AlarmClockInfo alarm = mAlarmManager.getNextAlarmClock(UserHandle.USER_CURRENT);
         final boolean hasAlarm = alarm != null && alarm.getTriggerTime() > 0;
         final boolean zenNone = mZen == Global.ZEN_MODE_NO_INTERRUPTIONS;
-        mService.setIcon(SLOT_ALARM_CLOCK, zenNone ? R.drawable.stat_sys_alarm_dim
-                : R.drawable.stat_sys_alarm, 0, null);
-        mService.setIconVisibility(SLOT_ALARM_CLOCK, mCurrentUserSetup && hasAlarm);
+        mIconController.setIcon(SLOT_ALARM_CLOCK, zenNone ? R.drawable.stat_sys_alarm_dim
+                : R.drawable.stat_sys_alarm, null);
+        mIconController.setIconVisibility(SLOT_ALARM_CLOCK, mCurrentUserSetup && hasAlarm);
     }
 
     private final void updateSimState(Intent intent) {
         String stateExtra = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
         if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(stateExtra)) {
             mSimState = IccCardConstants.State.ABSENT;
-        }
-        else if (IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR.equals(stateExtra)) {
+        } else if (IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR.equals(stateExtra)) {
             mSimState = IccCardConstants.State.CARD_IO_ERROR;
-        }
-        else if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(stateExtra)) {
+        } else if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(stateExtra)) {
             mSimState = IccCardConstants.State.READY;
-        }
-        else if (IccCardConstants.INTENT_VALUE_ICC_LOCKED.equals(stateExtra)) {
+        } else if (IccCardConstants.INTENT_VALUE_ICC_LOCKED.equals(stateExtra)) {
             final String lockedReason =
                     intent.getStringExtra(IccCardConstants.INTENT_KEY_LOCKED_REASON);
             if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PIN.equals(lockedReason)) {
                 mSimState = IccCardConstants.State.PIN_REQUIRED;
-            }
-            else if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PUK.equals(lockedReason)) {
+            } else if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PUK.equals(lockedReason)) {
                 mSimState = IccCardConstants.State.PUK_REQUIRED;
-            }
-            else {
+            } else {
                 mSimState = IccCardConstants.State.NETWORK_LOCKED;
             }
         } else {
@@ -270,18 +260,18 @@ public class PhoneStatusBarPolicy implements Callback {
         }
 
         if (zenVisible) {
-            mService.setIcon(SLOT_ZEN, zenIconId, 0, zenDescription);
+            mIconController.setIcon(SLOT_ZEN, zenIconId, zenDescription);
         }
         if (zenVisible != mZenVisible) {
-            mService.setIconVisibility(SLOT_ZEN, zenVisible);
+            mIconController.setIconVisibility(SLOT_ZEN, zenVisible);
             mZenVisible = zenVisible;
         }
 
         if (volumeVisible) {
-            mService.setIcon(SLOT_VOLUME, volumeIconId, 0, volumeDescription);
+            mIconController.setIcon(SLOT_VOLUME, volumeIconId, volumeDescription);
         }
         if (volumeVisible != mVolumeVisible) {
-            mService.setIconVisibility(SLOT_VOLUME, volumeVisible);
+            mIconController.setIconVisibility(SLOT_VOLUME, volumeVisible);
             mVolumeVisible = volumeVisible;
         }
         updateAlarm();
@@ -310,8 +300,8 @@ public class PhoneStatusBarPolicy implements Callback {
             }
         }
 
-        mService.setIcon(SLOT_BLUETOOTH, iconId, 0, contentDescription);
-        mService.setIconVisibility(SLOT_BLUETOOTH, bluetoothEnabled);
+        mIconController.setIcon(SLOT_BLUETOOTH, iconId, contentDescription);
+        mIconController.setIconVisibility(SLOT_BLUETOOTH, bluetoothEnabled);
     }
 
     private final void updateTTY(Intent intent) {
@@ -324,13 +314,13 @@ public class PhoneStatusBarPolicy implements Callback {
         if (enabled) {
             // TTY is on
             if (DEBUG) Log.v(TAG, "updateTTY: set TTY on");
-            mService.setIcon(SLOT_TTY, R.drawable.stat_sys_tty_mode, 0,
+            mIconController.setIcon(SLOT_TTY, R.drawable.stat_sys_tty_mode,
                     mContext.getString(R.string.accessibility_tty_enabled));
-            mService.setIconVisibility(SLOT_TTY, true);
+            mIconController.setIconVisibility(SLOT_TTY, true);
         } else {
             // TTY is off
             if (DEBUG) Log.v(TAG, "updateTTY: set TTY off");
-            mService.setIconVisibility(SLOT_TTY, false);
+            mIconController.setIconVisibility(SLOT_TTY, false);
         }
     }
 
@@ -346,9 +336,9 @@ public class PhoneStatusBarPolicy implements Callback {
         if (DEBUG) Log.v(TAG, "updateCast: isCasting: " + isCasting);
         mHandler.removeCallbacks(mRemoveCastIconRunnable);
         if (isCasting) {
-            mService.setIcon(SLOT_CAST, R.drawable.stat_sys_cast, 0,
+            mIconController.setIcon(SLOT_CAST, R.drawable.stat_sys_cast,
                     mContext.getString(R.string.accessibility_casting));
-            mService.setIconVisibility(SLOT_CAST, true);
+            mIconController.setIconVisibility(SLOT_CAST, true);
         } else {
             // don't turn off the screen-record icon for a few seconds, just to make sure the user
             // has seen it
@@ -392,17 +382,19 @@ public class PhoneStatusBarPolicy implements Callback {
         final boolean showIcon;
         if (mManagedProfileFocused && !mKeyguardVisible) {
             showIcon = true;
-            mService.setIcon(SLOT_MANAGED_PROFILE, R.drawable.stat_sys_managed_profile_status, 0,
+            mIconController.setIcon(SLOT_MANAGED_PROFILE,
+                    R.drawable.stat_sys_managed_profile_status,
                     mContext.getString(R.string.accessibility_managed_profile));
         } else if (mManagedProfileInQuietMode) {
             showIcon = true;
-            mService.setIcon(SLOT_MANAGED_PROFILE, R.drawable.stat_sys_managed_profile_status_off, 0,
+            mIconController.setIcon(SLOT_MANAGED_PROFILE,
+                    R.drawable.stat_sys_managed_profile_status_off,
                     mContext.getString(R.string.accessibility_managed_profile));
         } else {
             showIcon = false;
         }
         if (mManagedProfileIconVisible != showIcon) {
-            mService.setIconVisibility(SLOT_MANAGED_PROFILE, showIcon);
+            mIconController.setIconVisibility(SLOT_MANAGED_PROFILE, showIcon);
             mManagedProfileIconVisible = showIcon;
         }
     }
@@ -431,7 +423,7 @@ public class PhoneStatusBarPolicy implements Callback {
     private final HotspotController.Callback mHotspotCallback = new HotspotController.Callback() {
         @Override
         public void onHotspotChanged(boolean enabled) {
-            mService.setIconVisibility(SLOT_HOTSPOT, enabled);
+            mIconController.setIconVisibility(SLOT_HOTSPOT, enabled);
         }
     };
 
index d5b980e..6172752 100644 (file)
@@ -21,9 +21,11 @@ import android.animation.ValueAnimator;
 import android.content.Context;
 import android.content.res.ColorStateList;
 import android.graphics.Color;
+import android.graphics.drawable.Icon;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.SystemClock;
+import android.os.UserHandle;
 import android.text.TextUtils;
 import android.util.ArraySet;
 import android.view.View;
@@ -33,7 +35,6 @@ import android.view.animation.Interpolator;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.TextView;
-
 import com.android.internal.statusbar.StatusBarIcon;
 import com.android.internal.util.NotificationColorUtil;
 import com.android.systemui.BatteryMeterView;
@@ -54,7 +55,7 @@ import java.util.ArrayList;
  * limited to: notification icons, signal cluster, additional status icons, and clock in the status
  * bar.
  */
-public class StatusBarIconController implements Tunable {
+public class StatusBarIconController extends StatusBarIconList implements Tunable {
 
     public static final long DEFAULT_TINT_ANIMATION_DURATION = 120;
 
@@ -146,23 +147,27 @@ public class StatusBarIconController implements Tunable {
         }
         // Remove all the icons.
         for (int i = views.size() - 1; i >= 0; i--) {
-            removeSystemIcon(views.get(i).getSlot(), i, i);
+            removeIcon(views.get(i).getSlot());
         }
         // Add them all back
         for (int i = 0; i < views.size(); i++) {
-            addSystemIcon(views.get(i).getSlot(), i, i, views.get(i).getStatusBarIcon());
+            setIcon(views.get(i).getSlot(), views.get(i).getStatusBarIcon());
         }
-    };
+    }
 
     public void updateResources() {
         mIconSize = mContext.getResources().getDimensionPixelSize(
                 com.android.internal.R.dimen.status_bar_icon_size);
         mIconHPadding = mContext.getResources().getDimensionPixelSize(
                 R.dimen.status_bar_icon_padding);
+        defineSlots(mContext.getResources().getStringArray(
+                com.android.internal.R.array.config_statusBarIcons));
         FontSizeUtils.updateFontSize(mClock, R.dimen.status_bar_clock_size);
     }
 
-    public void addSystemIcon(String slot, int index, int viewIndex, StatusBarIcon icon) {
+    private void addSystemIcon(int index, StatusBarIcon icon) {
+        String slot = getSlot(index);
+        int viewIndex = getViewIndex(index);
         boolean blocked = mIconBlacklist.contains(slot);
         StatusBarIconView view = new StatusBarIconView(mContext, slot, null, blocked);
         view.set(icon);
@@ -175,8 +180,61 @@ public class StatusBarIconController implements Tunable {
         applyIconTint();
     }
 
-    public void updateSystemIcon(String slot, int index, int viewIndex,
-            StatusBarIcon old, StatusBarIcon icon) {
+    public void setIcon(String slot, int resourceId, CharSequence contentDescription) {
+        int index = getSlotIndex(slot);
+        StatusBarIcon icon = getIcon(index);
+        if (icon == null) {
+            icon = new StatusBarIcon(UserHandle.SYSTEM, mContext.getPackageName(),
+                    Icon.createWithResource(mContext, resourceId), 0, 0, contentDescription);
+            setIcon(slot, icon);
+        } else {
+            icon.icon = Icon.createWithResource(mContext, resourceId);
+            icon.contentDescription = contentDescription;
+            handleSet(index, icon);
+        }
+    }
+
+    public void setIcon(String slot, StatusBarIcon icon) {
+        setIcon(getSlotIndex(slot), icon);
+    }
+
+    public void removeIcon(String slot) {
+        int index = getSlotIndex(slot);
+        if (getIcon(index) == null) {
+            return;
+        }
+        super.removeIcon(index);
+        int viewIndex = getViewIndex(index);
+        mStatusIcons.removeViewAt(viewIndex);
+        mStatusIconsKeyguard.removeViewAt(viewIndex);
+    }
+
+    public void setIconVisibility(String slot, boolean visibility) {
+        int index = getSlotIndex(slot);
+        StatusBarIcon icon = getIcon(index);
+        if (icon == null || icon.visible == visibility) {
+            return;
+        }
+        icon.visible = visibility;
+        handleSet(index, icon);
+    }
+
+    @Override
+    public void setIcon(int index, StatusBarIcon icon) {
+        boolean isNew = getIcon(index) == null;
+        super.setIcon(index, icon);
+        if (icon == null) {
+            return;
+        }
+        if (isNew) {
+            addSystemIcon(index, icon);
+        } else {
+            handleSet(index, icon);
+        }
+    }
+
+    private void handleSet(int index, StatusBarIcon icon) {
+        int viewIndex = getViewIndex(index);
         StatusBarIconView view = (StatusBarIconView) mStatusIcons.getChildAt(viewIndex);
         view.set(icon);
         view = (StatusBarIconView) mStatusIconsKeyguard.getChildAt(viewIndex);
@@ -184,11 +242,6 @@ public class StatusBarIconController implements Tunable {
         applyIconTint();
     }
 
-    public void removeSystemIcon(String slot, int index, int viewIndex) {
-        mStatusIcons.removeViewAt(viewIndex);
-        mStatusIconsKeyguard.removeViewAt(viewIndex);
-    }
-
     public void updateNotificationIcons(NotificationData notificationData) {
         final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                 mIconSize + 2*mIconHPadding, mPhoneStatusBar.getStatusBarHeight());
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarIconList.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarIconList.java
new file mode 100644 (file)
index 0000000..62d6b76
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2015 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.phone;
+
+import com.android.internal.statusbar.StatusBarIcon;
+
+import java.io.PrintWriter;
+import java.util.ArrayList;
+
+public class StatusBarIconList {
+    private ArrayList<String> mSlots = new ArrayList<>();
+    private ArrayList<StatusBarIcon> mIcons = new ArrayList<>();
+
+    public void defineSlots(String[] slots) {
+        final int N = slots.length;
+        for (int i=0; i < N; i++) {
+            mSlots.add(slots[i]);
+            mIcons.add(null);
+        }
+    }
+
+    public int getSlotIndex(String slot) {
+        final int N = mSlots.size();
+        for (int i=0; i<N; i++) {
+            if (slot.equals(mSlots.get(i))) {
+                return i;
+            }
+        }
+        // Auto insert new items at the beginning.
+        mSlots.add(0, slot);
+        mIcons.add(0, null);
+        return 0;
+    }
+
+    public int size() {
+        return mSlots.size();
+    }
+
+    public void setIcon(int index, StatusBarIcon icon) {
+        mIcons.set(index, icon);
+    }
+
+    public void removeIcon(int index) {
+        mIcons.set(index, null);
+    }
+
+    public String getSlot(int index) {
+        return mSlots.get(index);
+    }
+
+    public StatusBarIcon getIcon(int index) {
+        return mIcons.get(index);
+    }
+
+    public int getViewIndex(int index) {
+        int count = 0;
+        for (int i = 0; i < index; i++) {
+            if (mIcons.get(i) != null) {
+                count++;
+            }
+        }
+        return count;
+    }
+
+    public void dump(PrintWriter pw) {
+        final int N = mSlots.size();
+        pw.println("Icon list:");
+        for (int i=0; i<N; i++) {
+            pw.printf("  %2d: (%s) %s\n", i, mSlots.get(i), mIcons.get(i));
+        }
+    }
+}
index 44b41c5..0406ae3 100644 (file)
@@ -33,16 +33,11 @@ import com.android.systemui.statusbar.NotificationData;
 public class TvStatusBar extends BaseStatusBar {
 
     @Override
-    public void addIcon(String slot, int index, int viewIndex, StatusBarIcon icon) {
+    public void setIcon(String slot, StatusBarIcon icon) {
     }
 
     @Override
-    public void updateIcon(String slot, int index, int viewIndex, StatusBarIcon old,
-            StatusBarIcon icon) {
-    }
-
-    @Override
-    public void removeIcon(String slot, int index, int viewIndex) {
+    public void removeIcon(String slot) {
     }
 
     @Override
index 2d38da5..2a1f46e 100644 (file)
 package com.android.server.statusbar;
 
 import android.app.StatusBarManager;
+import android.content.Context;
+import android.content.pm.PackageManager;
 import android.os.Binder;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.IBinder;
 import android.os.RemoteException;
 import android.os.UserHandle;
-import android.content.Context;
-import android.content.pm.PackageManager;
-import android.content.res.Resources;
+import android.util.ArrayMap;
 import android.util.Slog;
-
 import com.android.internal.statusbar.IStatusBar;
 import com.android.internal.statusbar.IStatusBarService;
 import com.android.internal.statusbar.NotificationVisibility;
 import com.android.internal.statusbar.StatusBarIcon;
-import com.android.internal.statusbar.StatusBarIconList;
 import com.android.server.LocalServices;
 import com.android.server.notification.NotificationDelegate;
 import com.android.server.wm.WindowManagerService;
@@ -56,7 +54,7 @@ public class StatusBarManagerService extends IStatusBarService.Stub {
     private Handler mHandler = new Handler();
     private NotificationDelegate mNotificationDelegate;
     private volatile IStatusBar mBar;
-    private StatusBarIconList mIcons = new StatusBarIconList();
+    private ArrayMap<String, StatusBarIcon> mIcons = new ArrayMap<>();
 
     // for disabling the status bar
     private final ArrayList<DisableRecord> mDisableRecords = new ArrayList<DisableRecord>();
@@ -96,9 +94,6 @@ public class StatusBarManagerService extends IStatusBarService.Stub {
         mContext = context;
         mWindowManager = windowManager;
 
-        final Resources res = context.getResources();
-        mIcons.defineSlots(res.getStringArray(com.android.internal.R.array.config_statusBarIcons));
-
         LocalServices.addService(StatusBarManagerInternal.class, mInternalService);
     }
 
@@ -300,19 +295,14 @@ public class StatusBarManagerService extends IStatusBarService.Stub {
         enforceStatusBar();
 
         synchronized (mIcons) {
-            int index = mIcons.getSlotIndex(slot);
-            if (index < 0) {
-                throw new SecurityException("invalid status bar icon slot: " + slot);
-            }
-
             StatusBarIcon icon = new StatusBarIcon(iconPackage, UserHandle.SYSTEM, iconId,
                     iconLevel, 0, contentDescription);
             //Slog.d(TAG, "setIcon slot=" + slot + " index=" + index + " icon=" + icon);
-            mIcons.setIcon(index, icon);
+            mIcons.put(slot, icon);
 
             if (mBar != null) {
                 try {
-                    mBar.setIcon(index, icon);
+                    mBar.setIcon(slot, icon);
                 } catch (RemoteException ex) {
                 }
             }
@@ -320,26 +310,20 @@ public class StatusBarManagerService extends IStatusBarService.Stub {
     }
 
     @Override
-    public void setIconVisibility(String slot, boolean visible) {
+    public void setIconVisibility(String slot, boolean visibility) {
         enforceStatusBar();
 
         synchronized (mIcons) {
-            int index = mIcons.getSlotIndex(slot);
-            if (index < 0) {
-                throw new SecurityException("invalid status bar icon slot: " + slot);
-            }
-
-            StatusBarIcon icon = mIcons.getIcon(index);
+            StatusBarIcon icon = mIcons.get(slot);
             if (icon == null) {
                 return;
             }
-
-            if (icon.visible != visible) {
-                icon.visible = visible;
+            if (icon.visible != visibility) {
+                icon.visible = visibility;
 
                 if (mBar != null) {
                     try {
-                        mBar.setIcon(index, icon);
+                        mBar.setIcon(slot, icon);
                     } catch (RemoteException ex) {
                     }
                 }
@@ -352,16 +336,11 @@ public class StatusBarManagerService extends IStatusBarService.Stub {
         enforceStatusBar();
 
         synchronized (mIcons) {
-            int index = mIcons.getSlotIndex(slot);
-            if (index < 0) {
-                throw new SecurityException("invalid status bar icon slot: " + slot);
-            }
-
-            mIcons.removeIcon(index);
+            mIcons.remove(slot);
 
             if (mBar != null) {
                 try {
-                    mBar.removeIcon(index);
+                    mBar.removeIcon(slot);
                 } catch (RemoteException ex) {
                 }
             }
@@ -583,14 +562,17 @@ public class StatusBarManagerService extends IStatusBarService.Stub {
     // Callbacks from the status bar service.
     // ================================================================================
     @Override
-    public void registerStatusBar(IStatusBar bar, StatusBarIconList iconList,
-            int switches[], List<IBinder> binders) {
+    public void registerStatusBar(IStatusBar bar, List<String> iconSlots,
+            List<StatusBarIcon> iconList, int switches[], List<IBinder> binders) {
         enforceStatusBarService();
 
         Slog.i(TAG, "registerStatusBar bar=" + bar);
         mBar = bar;
         synchronized (mIcons) {
-            iconList.copyFrom(mIcons);
+            for (String slot : mIcons.keySet()) {
+                iconSlots.add(slot);
+                iconList.add(mIcons.get(slot));
+            }
         }
         synchronized (mLock) {
             switches[0] = gatherDisableActionsLocked(mCurrentUserId, 1);
@@ -812,10 +794,6 @@ public class StatusBarManagerService extends IStatusBarService.Stub {
             return;
         }
 
-        synchronized (mIcons) {
-            mIcons.dump(pw);
-        }
-
         synchronized (mLock) {
             pw.println("  mDisabled1=0x" + Integer.toHexString(mDisabled1));
             pw.println("  mDisabled2=0x" + Integer.toHexString(mDisabled2));