StatusBarManagerService.java revision 98edc951712823dbf5db2b7e9c203a0e98fc616b
19066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/*
29066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Copyright (C) 2007 The Android Open Source Project
39066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
49066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License");
59066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * you may not use this file except in compliance with the License.
69066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * You may obtain a copy of the License at
79066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
89066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *      http://www.apache.org/licenses/LICENSE-2.0
99066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Unless required by applicable law or agreed to in writing, software
119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS,
129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * See the License for the specific language governing permissions and
149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * limitations under the License.
159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
177a0f36bd93ad8a5b8cb3e1fe56dbdb43a0ad3a57Joe Onoratopackage com.android.server;
189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.app.StatusBarManager;
209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.content.BroadcastReceiver;
219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.content.Context;
229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.content.Intent;
239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.content.pm.PackageManager;
249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.content.res.Resources;
259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.Binder;
26f3f0e053f0cc66249a11639eb67d0cdc2da26dedJoe Onoratoimport android.os.Handler;
276179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganovimport android.os.IBinder;
286179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganovimport android.os.RemoteException;
2998edc951712823dbf5db2b7e9c203a0e98fc616bAmith Yamasaniimport android.os.UserHandle;
308a9b22056b13477f59df934928c00c58b5871c95Joe Onoratoimport android.util.Slog;
310cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato
320cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onoratoimport com.android.internal.statusbar.IStatusBar;
330cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onoratoimport com.android.internal.statusbar.IStatusBarService;
340cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onoratoimport com.android.internal.statusbar.StatusBarIcon;
350cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onoratoimport com.android.internal.statusbar.StatusBarIconList;
3618e69dfc7235f8a4bfe257f9d1c43539049a22ceJoe Onoratoimport com.android.internal.statusbar.StatusBarNotification;
37a924dc0db952fe32509435fdb8dc9c84a9e181f3Dianne Hackbornimport com.android.server.wm.WindowManagerService;
38105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project
399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport java.io.FileDescriptor;
409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport java.io.PrintWriter;
419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport java.util.ArrayList;
429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport java.util.HashMap;
4375199e3ddcf7886c8ee5fbf8b486a8c21335bf14Joe Onoratoimport java.util.List;
4475199e3ddcf7886c8ee5fbf8b486a8c21335bf14Joe Onoratoimport java.util.Map;
459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/**
48f3f0e053f0cc66249a11639eb67d0cdc2da26dedJoe Onorato * A note on locking:  We rely on the fact that calls onto mBar are oneway or
49f3f0e053f0cc66249a11639eb67d0cdc2da26dedJoe Onorato * if they are local, that they just enqueue messages to not deadlock.
509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
51089de88fc2f08d284cf8031aa33cff06011a4162Joe Onoratopublic class StatusBarManagerService extends IStatusBarService.Stub
522992ea782fa61780d8e0de7a36a2a84622f8694bJeff Brown    implements WindowManagerService.OnHardKeyboardStatusChangeListener
539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{
544762c2d75a55e0854bbff2f996748116d4ab1a37Joe Onorato    static final String TAG = "StatusBarManagerService";
55431bb2269532f2514861b908d5fafda8fa64da79Joe Onorato    static final boolean SPEW = false;
56df7dbb68d330eae88c1ca6d03390dc8c18386871Joe Onorato
57f3f0e053f0cc66249a11639eb67d0cdc2da26dedJoe Onorato    final Context mContext;
582992ea782fa61780d8e0de7a36a2a84622f8694bJeff Brown    final WindowManagerService mWindowManager;
59f3f0e053f0cc66249a11639eb67d0cdc2da26dedJoe Onorato    Handler mHandler = new Handler();
60f3f0e053f0cc66249a11639eb67d0cdc2da26dedJoe Onorato    NotificationCallbacks mNotificationCallbacks;
614762c2d75a55e0854bbff2f996748116d4ab1a37Joe Onorato    volatile IStatusBar mBar;
62f3f0e053f0cc66249a11639eb67d0cdc2da26dedJoe Onorato    StatusBarIconList mIcons = new StatusBarIconList();
6375199e3ddcf7886c8ee5fbf8b486a8c21335bf14Joe Onorato    HashMap<IBinder,StatusBarNotification> mNotifications
6475199e3ddcf7886c8ee5fbf8b486a8c21335bf14Joe Onorato            = new HashMap<IBinder,StatusBarNotification>();
65f3f0e053f0cc66249a11639eb67d0cdc2da26dedJoe Onorato
66f3f0e053f0cc66249a11639eb67d0cdc2da26dedJoe Onorato    // for disabling the status bar
67f3f0e053f0cc66249a11639eb67d0cdc2da26dedJoe Onorato    ArrayList<DisableRecord> mDisableRecords = new ArrayList<DisableRecord>();
687bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato    IBinder mSysUiVisToken = new Binder();
69f3f0e053f0cc66249a11639eb67d0cdc2da26dedJoe Onorato    int mDisabled = 0;
709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
719305647eb61bb60a1f42481a0c0d208dc9bbe965Joe Onorato    Object mLock = new Object();
7260ee25643e0a7b8841063a4e97b0f18c51807e91Daniel Sandler    // encompasses lights-out mode and other flags defined on View
7360ee25643e0a7b8841063a4e97b0f18c51807e91Daniel Sandler    int mSystemUiVisibility = 0;
74e02d808abf370965c3c4e4d38af11bc69110fde2Daniel Sandler    boolean mMenuVisible = false;
75857fd9b8562c29913e03ed29288bd1802d37dc60Joe Onorato    int mImeWindowVis = 0;
76857fd9b8562c29913e03ed29288bd1802d37dc60Joe Onorato    int mImeBackDisposition;
77857fd9b8562c29913e03ed29288bd1802d37dc60Joe Onorato    IBinder mImeToken = null;
7806487a58be22b100daf3f950b9a1d25c3ea42aa2satok
799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private class DisableRecord implements IBinder.DeathRecipient {
809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        String pkg;
819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        int what;
829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        IBinder token;
839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void binderDied() {
858a9b22056b13477f59df934928c00c58b5871c95Joe Onorato            Slog.i(TAG, "binder died for pkg=" + pkg);
869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            disable(0, token, pkg);
87fff2fda0199dedbf1079454dca98a81190dce765Suchi Amalapurapu            token.unlinkToDeath(this, 0);
889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public interface NotificationCallbacks {
929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        void onSetDisabled(int status);
939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        void onClearAll();
946ecaff15836581336b1e8fad6ac42f3ff4a13544Fred Quintana        void onNotificationClick(String pkg, String tag, int id);
950f0b11c8719495ce559b93366fe9cd79782d791cDaniel Sandler        void onNotificationClear(String pkg, String tag, int id);
969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        void onPanelRevealed();
979d39d0cb361c5d3bba04a6bacf299be2162a6e92Dianne Hackborn        void onNotificationError(String pkg, String tag, int id,
989d39d0cb361c5d3bba04a6bacf299be2162a6e92Dianne Hackborn                int uid, int initialPid, String message);
999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Construct the service, add the status bar view to the window manager
1039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
1042992ea782fa61780d8e0de7a36a2a84622f8694bJeff Brown    public StatusBarManagerService(Context context, WindowManagerService windowManager) {
1059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mContext = context;
1062992ea782fa61780d8e0de7a36a2a84622f8694bJeff Brown        mWindowManager = windowManager;
1072992ea782fa61780d8e0de7a36a2a84622f8694bJeff Brown        mWindowManager.setOnHardKeyboardStatusChangeListener(this);
1080cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato
1090cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato        final Resources res = context.getResources();
11075144ea38e79e3827e69a9f5b53a6fd3a74c4df5Joe Onorato        mIcons.defineSlots(res.getStringArray(com.android.internal.R.array.config_statusBarIcons));
1119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public void setNotificationCallbacks(NotificationCallbacks listener) {
1149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mNotificationCallbacks = listener;
1159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    // ================================================================================
11825f95f92005594f2ef094001c54cb4c39eec3adeJoe Onorato    // From IStatusBarService
1199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    // ================================================================================
120f3f0e053f0cc66249a11639eb67d0cdc2da26dedJoe Onorato    public void expand() {
1219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        enforceExpandStatusBar();
1224762c2d75a55e0854bbff2f996748116d4ab1a37Joe Onorato
1234762c2d75a55e0854bbff2f996748116d4ab1a37Joe Onorato        if (mBar != null) {
1244762c2d75a55e0854bbff2f996748116d4ab1a37Joe Onorato            try {
1254762c2d75a55e0854bbff2f996748116d4ab1a37Joe Onorato                mBar.animateExpand();
1264762c2d75a55e0854bbff2f996748116d4ab1a37Joe Onorato            } catch (RemoteException ex) {
1274762c2d75a55e0854bbff2f996748116d4ab1a37Joe Onorato            }
1284762c2d75a55e0854bbff2f996748116d4ab1a37Joe Onorato        }
1299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
131f3f0e053f0cc66249a11639eb67d0cdc2da26dedJoe Onorato    public void collapse() {
1329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        enforceExpandStatusBar();
1339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1344762c2d75a55e0854bbff2f996748116d4ab1a37Joe Onorato        if (mBar != null) {
1354762c2d75a55e0854bbff2f996748116d4ab1a37Joe Onorato            try {
1364762c2d75a55e0854bbff2f996748116d4ab1a37Joe Onorato                mBar.animateCollapse();
1374762c2d75a55e0854bbff2f996748116d4ab1a37Joe Onorato            } catch (RemoteException ex) {
1384762c2d75a55e0854bbff2f996748116d4ab1a37Joe Onorato            }
1394762c2d75a55e0854bbff2f996748116d4ab1a37Joe Onorato        }
1409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public void disable(int what, IBinder token, String pkg) {
1439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        enforceStatusBar();
144f3f0e053f0cc66249a11639eb67d0cdc2da26dedJoe Onorato
1457bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato        synchronized (mLock) {
1467bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato            disableLocked(what, token, pkg);
1477bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato        }
1487bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato    }
1497bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato
1507bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato    private void disableLocked(int what, IBinder token, String pkg) {
151f3f0e053f0cc66249a11639eb67d0cdc2da26dedJoe Onorato        // It's important that the the callback and the call to mBar get done
152f3f0e053f0cc66249a11639eb67d0cdc2da26dedJoe Onorato        // in the same order when multiple threads are calling this function
153f3f0e053f0cc66249a11639eb67d0cdc2da26dedJoe Onorato        // so they are paired correctly.  The messages on the handler will be
154f3f0e053f0cc66249a11639eb67d0cdc2da26dedJoe Onorato        // handled in the order they were enqueued, but will be outside the lock.
1557bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato        manageDisableListLocked(what, token, pkg);
1567bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato        final int net = gatherDisableActionsLocked();
1577bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato        if (net != mDisabled) {
1587bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato            mDisabled = net;
1597bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato            mHandler.post(new Runnable() {
1607bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato                    public void run() {
1617bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato                        mNotificationCallbacks.onSetDisabled(net);
162f3f0e053f0cc66249a11639eb67d0cdc2da26dedJoe Onorato                    }
1637bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato                });
1647bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato            if (mBar != null) {
1657bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato                try {
1667bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato                    mBar.disable(net);
1677bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato                } catch (RemoteException ex) {
168f3f0e053f0cc66249a11639eb67d0cdc2da26dedJoe Onorato                }
1699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
1709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
1719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1736179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganov    public void setIcon(String slot, String iconPackage, int iconId, int iconLevel,
1746179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganov            String contentDescription) {
1759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        enforceStatusBar();
1760cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato
1770cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato        synchronized (mIcons) {
1780cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato            int index = mIcons.getSlotIndex(slot);
1790cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato            if (index < 0) {
1800cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato                throw new SecurityException("invalid status bar icon slot: " + slot);
1810cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato            }
1820cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato
18398edc951712823dbf5db2b7e9c203a0e98fc616bAmith Yamasani            StatusBarIcon icon = new StatusBarIcon(iconPackage, UserHandle.OWNER, iconId,
18498edc951712823dbf5db2b7e9c203a0e98fc616bAmith Yamasani                    iconLevel, 0,
1856179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganov                    contentDescription);
18666d7d01ed91968f4ed2e2669fd306aa2af61cd16Joe Onorato            //Slog.d(TAG, "setIcon slot=" + slot + " index=" + index + " icon=" + icon);
1870cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato            mIcons.setIcon(index, icon);
1880cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato
1890cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato            if (mBar != null) {
1900cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato                try {
1910cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato                    mBar.setIcon(index, icon);
1920cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato                } catch (RemoteException ex) {
1930cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato                }
1940cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato            }
1950cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato        }
1969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1980cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato    public void setIconVisibility(String slot, boolean visible) {
1999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        enforceStatusBar();
2000cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato
201514ad663f0a8b239cc59409175e0bd489c591aa0Joe Onorato        synchronized (mIcons) {
202514ad663f0a8b239cc59409175e0bd489c591aa0Joe Onorato            int index = mIcons.getSlotIndex(slot);
203514ad663f0a8b239cc59409175e0bd489c591aa0Joe Onorato            if (index < 0) {
204514ad663f0a8b239cc59409175e0bd489c591aa0Joe Onorato                throw new SecurityException("invalid status bar icon slot: " + slot);
205514ad663f0a8b239cc59409175e0bd489c591aa0Joe Onorato            }
206514ad663f0a8b239cc59409175e0bd489c591aa0Joe Onorato
207514ad663f0a8b239cc59409175e0bd489c591aa0Joe Onorato            StatusBarIcon icon = mIcons.getIcon(index);
208514ad663f0a8b239cc59409175e0bd489c591aa0Joe Onorato            if (icon == null) {
209514ad663f0a8b239cc59409175e0bd489c591aa0Joe Onorato                return;
210514ad663f0a8b239cc59409175e0bd489c591aa0Joe Onorato            }
211514ad663f0a8b239cc59409175e0bd489c591aa0Joe Onorato
212514ad663f0a8b239cc59409175e0bd489c591aa0Joe Onorato            if (icon.visible != visible) {
213514ad663f0a8b239cc59409175e0bd489c591aa0Joe Onorato                icon.visible = visible;
214514ad663f0a8b239cc59409175e0bd489c591aa0Joe Onorato
215514ad663f0a8b239cc59409175e0bd489c591aa0Joe Onorato                if (mBar != null) {
216514ad663f0a8b239cc59409175e0bd489c591aa0Joe Onorato                    try {
217514ad663f0a8b239cc59409175e0bd489c591aa0Joe Onorato                        mBar.setIcon(index, icon);
218514ad663f0a8b239cc59409175e0bd489c591aa0Joe Onorato                    } catch (RemoteException ex) {
219514ad663f0a8b239cc59409175e0bd489c591aa0Joe Onorato                    }
220514ad663f0a8b239cc59409175e0bd489c591aa0Joe Onorato                }
221514ad663f0a8b239cc59409175e0bd489c591aa0Joe Onorato            }
222514ad663f0a8b239cc59409175e0bd489c591aa0Joe Onorato        }
2239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2250cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato    public void removeIcon(String slot) {
2269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        enforceStatusBar();
2270cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato
2280cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato        synchronized (mIcons) {
2290cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato            int index = mIcons.getSlotIndex(slot);
2300cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato            if (index < 0) {
2310cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato                throw new SecurityException("invalid status bar icon slot: " + slot);
2320cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato            }
2330cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato
2340cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato            mIcons.removeIcon(index);
2350cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato
2360cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato            if (mBar != null) {
2370cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato                try {
2380cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato                    mBar.removeIcon(index);
2390cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato                } catch (RemoteException ex) {
2400cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato                }
2410cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato            }
2420cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato        }
2439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
245e02d808abf370965c3c4e4d38af11bc69110fde2Daniel Sandler    /**
246e02d808abf370965c3c4e4d38af11bc69110fde2Daniel Sandler     * Hide or show the on-screen Menu key. Only call this from the window manager, typically in
247e02d808abf370965c3c4e4d38af11bc69110fde2Daniel Sandler     * response to a window with FLAG_NEEDS_MENU_KEY set.
248e02d808abf370965c3c4e4d38af11bc69110fde2Daniel Sandler     */
2497d04932ef5c001769ccef244f551b75773f1666bDianne Hackborn    public void topAppWindowChanged(final boolean menuVisible) {
250e02d808abf370965c3c4e4d38af11bc69110fde2Daniel Sandler        enforceStatusBar();
251e02d808abf370965c3c4e4d38af11bc69110fde2Daniel Sandler
2527d04932ef5c001769ccef244f551b75773f1666bDianne Hackborn        if (SPEW) Slog.d(TAG, (menuVisible?"showing":"hiding") + " MENU key");
253e02d808abf370965c3c4e4d38af11bc69110fde2Daniel Sandler
254e02d808abf370965c3c4e4d38af11bc69110fde2Daniel Sandler        synchronized(mLock) {
2557d04932ef5c001769ccef244f551b75773f1666bDianne Hackborn            mMenuVisible = menuVisible;
2567d04932ef5c001769ccef244f551b75773f1666bDianne Hackborn            mHandler.post(new Runnable() {
2577d04932ef5c001769ccef244f551b75773f1666bDianne Hackborn                    public void run() {
2587d04932ef5c001769ccef244f551b75773f1666bDianne Hackborn                        if (mBar != null) {
2597d04932ef5c001769ccef244f551b75773f1666bDianne Hackborn                            try {
2607d04932ef5c001769ccef244f551b75773f1666bDianne Hackborn                                mBar.topAppWindowChanged(menuVisible);
2617d04932ef5c001769ccef244f551b75773f1666bDianne Hackborn                            } catch (RemoteException ex) {
262e02d808abf370965c3c4e4d38af11bc69110fde2Daniel Sandler                            }
263e02d808abf370965c3c4e4d38af11bc69110fde2Daniel Sandler                        }
2647d04932ef5c001769ccef244f551b75773f1666bDianne Hackborn                    }
2657d04932ef5c001769ccef244f551b75773f1666bDianne Hackborn                });
266e02d808abf370965c3c4e4d38af11bc69110fde2Daniel Sandler        }
267e02d808abf370965c3c4e4d38af11bc69110fde2Daniel Sandler    }
268e02d808abf370965c3c4e4d38af11bc69110fde2Daniel Sandler
269857fd9b8562c29913e03ed29288bd1802d37dc60Joe Onorato    public void setImeWindowStatus(final IBinder token, final int vis, final int backDisposition) {
27006487a58be22b100daf3f950b9a1d25c3ea42aa2satok        enforceStatusBar();
27106487a58be22b100daf3f950b9a1d25c3ea42aa2satok
272857fd9b8562c29913e03ed29288bd1802d37dc60Joe Onorato        if (SPEW) {
273857fd9b8562c29913e03ed29288bd1802d37dc60Joe Onorato            Slog.d(TAG, "swetImeWindowStatus vis=" + vis + " backDisposition=" + backDisposition);
274857fd9b8562c29913e03ed29288bd1802d37dc60Joe Onorato        }
27506487a58be22b100daf3f950b9a1d25c3ea42aa2satok
27606487a58be22b100daf3f950b9a1d25c3ea42aa2satok        synchronized(mLock) {
277857fd9b8562c29913e03ed29288bd1802d37dc60Joe Onorato            // In case of IME change, we need to call up setImeWindowStatus() regardless of
278857fd9b8562c29913e03ed29288bd1802d37dc60Joe Onorato            // mImeWindowVis because mImeWindowVis may not have been set to false when the
27906e0744e9e1a04a07e2e1bf9279124223bd674dasatok            // previous IME was destroyed.
280857fd9b8562c29913e03ed29288bd1802d37dc60Joe Onorato            mImeWindowVis = vis;
281857fd9b8562c29913e03ed29288bd1802d37dc60Joe Onorato            mImeBackDisposition = backDisposition;
282857fd9b8562c29913e03ed29288bd1802d37dc60Joe Onorato            mImeToken = token;
28306e0744e9e1a04a07e2e1bf9279124223bd674dasatok            mHandler.post(new Runnable() {
28406e0744e9e1a04a07e2e1bf9279124223bd674dasatok                public void run() {
28506e0744e9e1a04a07e2e1bf9279124223bd674dasatok                    if (mBar != null) {
28606e0744e9e1a04a07e2e1bf9279124223bd674dasatok                        try {
287857fd9b8562c29913e03ed29288bd1802d37dc60Joe Onorato                            mBar.setImeWindowStatus(token, vis, backDisposition);
28806e0744e9e1a04a07e2e1bf9279124223bd674dasatok                        } catch (RemoteException ex) {
28906487a58be22b100daf3f950b9a1d25c3ea42aa2satok                        }
29006487a58be22b100daf3f950b9a1d25c3ea42aa2satok                    }
29106e0744e9e1a04a07e2e1bf9279124223bd674dasatok                }
29206e0744e9e1a04a07e2e1bf9279124223bd674dasatok            });
29306487a58be22b100daf3f950b9a1d25c3ea42aa2satok        }
29406487a58be22b100daf3f950b9a1d25c3ea42aa2satok    }
29506487a58be22b100daf3f950b9a1d25c3ea42aa2satok
2963a3a6cfd8ec12208ca75c0d0d871d19d76c34194Dianne Hackborn    public void setSystemUiVisibility(int vis, int mask) {
29755bf3809b98dad0b8268804e684d63ea59124148Joe Onorato        // also allows calls from window manager which is in this process.
298f63b0f44eb53f535a65bd83dbc1d8b95abc501daJoe Onorato        enforceStatusBarService();
299f63b0f44eb53f535a65bd83dbc1d8b95abc501daJoe Onorato
3004519a02608b9e02a2c0dbc7dff37c21167db8f24Jeff Sharkey        if (SPEW) Slog.d(TAG, "setSystemUiVisibility(0x" + Integer.toHexString(vis) + ")");
30160ee25643e0a7b8841063a4e97b0f18c51807e91Daniel Sandler
302f63b0f44eb53f535a65bd83dbc1d8b95abc501daJoe Onorato        synchronized (mLock) {
3033a3a6cfd8ec12208ca75c0d0d871d19d76c34194Dianne Hackborn            updateUiVisibilityLocked(vis, mask);
3047bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato            disableLocked(vis & StatusBarManager.DISABLE_MASK, mSysUiVisToken,
3057bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato                    "WindowManager.LayoutParams");
306f63b0f44eb53f535a65bd83dbc1d8b95abc501daJoe Onorato        }
307f63b0f44eb53f535a65bd83dbc1d8b95abc501daJoe Onorato    }
308f63b0f44eb53f535a65bd83dbc1d8b95abc501daJoe Onorato
3093a3a6cfd8ec12208ca75c0d0d871d19d76c34194Dianne Hackborn    private void updateUiVisibilityLocked(final int vis, final int mask) {
31060ee25643e0a7b8841063a4e97b0f18c51807e91Daniel Sandler        if (mSystemUiVisibility != vis) {
31160ee25643e0a7b8841063a4e97b0f18c51807e91Daniel Sandler            mSystemUiVisibility = vis;
312f63b0f44eb53f535a65bd83dbc1d8b95abc501daJoe Onorato            mHandler.post(new Runnable() {
313f63b0f44eb53f535a65bd83dbc1d8b95abc501daJoe Onorato                    public void run() {
314f63b0f44eb53f535a65bd83dbc1d8b95abc501daJoe Onorato                        if (mBar != null) {
315f63b0f44eb53f535a65bd83dbc1d8b95abc501daJoe Onorato                            try {
3163a3a6cfd8ec12208ca75c0d0d871d19d76c34194Dianne Hackborn                                mBar.setSystemUiVisibility(vis, mask);
317f63b0f44eb53f535a65bd83dbc1d8b95abc501daJoe Onorato                            } catch (RemoteException ex) {
3189305647eb61bb60a1f42481a0c0d208dc9bbe965Joe Onorato                            }
3199305647eb61bb60a1f42481a0c0d208dc9bbe965Joe Onorato                        }
320f63b0f44eb53f535a65bd83dbc1d8b95abc501daJoe Onorato                    }
321f63b0f44eb53f535a65bd83dbc1d8b95abc501daJoe Onorato                });
3229305647eb61bb60a1f42481a0c0d208dc9bbe965Joe Onorato        }
3239305647eb61bb60a1f42481a0c0d208dc9bbe965Joe Onorato    }
3249305647eb61bb60a1f42481a0c0d208dc9bbe965Joe Onorato
3252992ea782fa61780d8e0de7a36a2a84622f8694bJeff Brown    public void setHardKeyboardEnabled(final boolean enabled) {
3262992ea782fa61780d8e0de7a36a2a84622f8694bJeff Brown        mHandler.post(new Runnable() {
3272992ea782fa61780d8e0de7a36a2a84622f8694bJeff Brown            public void run() {
3282992ea782fa61780d8e0de7a36a2a84622f8694bJeff Brown                mWindowManager.setHardKeyboardEnabled(enabled);
3292992ea782fa61780d8e0de7a36a2a84622f8694bJeff Brown            }
3302992ea782fa61780d8e0de7a36a2a84622f8694bJeff Brown        });
3312992ea782fa61780d8e0de7a36a2a84622f8694bJeff Brown    }
3322992ea782fa61780d8e0de7a36a2a84622f8694bJeff Brown
3332992ea782fa61780d8e0de7a36a2a84622f8694bJeff Brown    @Override
3342992ea782fa61780d8e0de7a36a2a84622f8694bJeff Brown    public void onHardKeyboardStatusChange(final boolean available, final boolean enabled) {
3352992ea782fa61780d8e0de7a36a2a84622f8694bJeff Brown        mHandler.post(new Runnable() {
3362992ea782fa61780d8e0de7a36a2a84622f8694bJeff Brown            public void run() {
3372992ea782fa61780d8e0de7a36a2a84622f8694bJeff Brown                if (mBar != null) {
3382992ea782fa61780d8e0de7a36a2a84622f8694bJeff Brown                    try {
3392992ea782fa61780d8e0de7a36a2a84622f8694bJeff Brown                        mBar.setHardKeyboardStatus(available, enabled);
3402992ea782fa61780d8e0de7a36a2a84622f8694bJeff Brown                    } catch (RemoteException ex) {
3412992ea782fa61780d8e0de7a36a2a84622f8694bJeff Brown                    }
3422992ea782fa61780d8e0de7a36a2a84622f8694bJeff Brown                }
3432992ea782fa61780d8e0de7a36a2a84622f8694bJeff Brown            }
3442992ea782fa61780d8e0de7a36a2a84622f8694bJeff Brown        });
3452992ea782fa61780d8e0de7a36a2a84622f8694bJeff Brown    }
3462992ea782fa61780d8e0de7a36a2a84622f8694bJeff Brown
3473b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka    @Override
3483b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka    public void toggleRecentApps() {
3493b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka        if (mBar != null) {
3503b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka            try {
3513b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka                mBar.toggleRecentApps();
3523b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka            } catch (RemoteException ex) {}
3533b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka        }
3543b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka    }
3553b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka
3567f2668c8469934ce83a5647977f6e74ab782cf07Michael Jurka    @Override
3577f2668c8469934ce83a5647977f6e74ab782cf07Michael Jurka    public void preloadRecentApps() {
3587f2668c8469934ce83a5647977f6e74ab782cf07Michael Jurka        if (mBar != null) {
3597f2668c8469934ce83a5647977f6e74ab782cf07Michael Jurka            try {
3607f2668c8469934ce83a5647977f6e74ab782cf07Michael Jurka                mBar.preloadRecentApps();
3617f2668c8469934ce83a5647977f6e74ab782cf07Michael Jurka            } catch (RemoteException ex) {}
3627f2668c8469934ce83a5647977f6e74ab782cf07Michael Jurka        }
3637f2668c8469934ce83a5647977f6e74ab782cf07Michael Jurka    }
3647f2668c8469934ce83a5647977f6e74ab782cf07Michael Jurka
3657f2668c8469934ce83a5647977f6e74ab782cf07Michael Jurka    @Override
3667f2668c8469934ce83a5647977f6e74ab782cf07Michael Jurka    public void cancelPreloadRecentApps() {
3677f2668c8469934ce83a5647977f6e74ab782cf07Michael Jurka        if (mBar != null) {
3687f2668c8469934ce83a5647977f6e74ab782cf07Michael Jurka            try {
3697f2668c8469934ce83a5647977f6e74ab782cf07Michael Jurka                mBar.cancelPreloadRecentApps();
3707f2668c8469934ce83a5647977f6e74ab782cf07Michael Jurka            } catch (RemoteException ex) {}
3717f2668c8469934ce83a5647977f6e74ab782cf07Michael Jurka        }
3727f2668c8469934ce83a5647977f6e74ab782cf07Michael Jurka    }
3737f2668c8469934ce83a5647977f6e74ab782cf07Michael Jurka
3749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private void enforceStatusBar() {
3750cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR,
376089de88fc2f08d284cf8031aa33cff06011a4162Joe Onorato                "StatusBarManagerService");
3779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private void enforceExpandStatusBar() {
3800cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.EXPAND_STATUS_BAR,
381089de88fc2f08d284cf8031aa33cff06011a4162Joe Onorato                "StatusBarManagerService");
3829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3848bc6c5141974dbc36a6fe416853f558921be9f24Joe Onorato    private void enforceStatusBarService() {
3858bc6c5141974dbc36a6fe416853f558921be9f24Joe Onorato        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR_SERVICE,
3868bc6c5141974dbc36a6fe416853f558921be9f24Joe Onorato                "StatusBarManagerService");
3878bc6c5141974dbc36a6fe416853f558921be9f24Joe Onorato    }
3888bc6c5141974dbc36a6fe416853f558921be9f24Joe Onorato
3894762c2d75a55e0854bbff2f996748116d4ab1a37Joe Onorato    // ================================================================================
3904762c2d75a55e0854bbff2f996748116d4ab1a37Joe Onorato    // Callbacks from the status bar service.
3914762c2d75a55e0854bbff2f996748116d4ab1a37Joe Onorato    // ================================================================================
39275199e3ddcf7886c8ee5fbf8b486a8c21335bf14Joe Onorato    public void registerStatusBar(IStatusBar bar, StatusBarIconList iconList,
3939305647eb61bb60a1f42481a0c0d208dc9bbe965Joe Onorato            List<IBinder> notificationKeys, List<StatusBarNotification> notifications,
394cd7cd2969f545ad061a9b4ecd0044f15eb1b4abbsatok            int switches[], List<IBinder> binders) {
3958bc6c5141974dbc36a6fe416853f558921be9f24Joe Onorato        enforceStatusBarService();
3968bc6c5141974dbc36a6fe416853f558921be9f24Joe Onorato
3970cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato        Slog.i(TAG, "registerStatusBar bar=" + bar);
3980cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato        mBar = bar;
39975199e3ddcf7886c8ee5fbf8b486a8c21335bf14Joe Onorato        synchronized (mIcons) {
40075199e3ddcf7886c8ee5fbf8b486a8c21335bf14Joe Onorato            iconList.copyFrom(mIcons);
40175199e3ddcf7886c8ee5fbf8b486a8c21335bf14Joe Onorato        }
40275199e3ddcf7886c8ee5fbf8b486a8c21335bf14Joe Onorato        synchronized (mNotifications) {
40375199e3ddcf7886c8ee5fbf8b486a8c21335bf14Joe Onorato            for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
40475199e3ddcf7886c8ee5fbf8b486a8c21335bf14Joe Onorato                notificationKeys.add(e.getKey());
40575199e3ddcf7886c8ee5fbf8b486a8c21335bf14Joe Onorato                notifications.add(e.getValue());
40675199e3ddcf7886c8ee5fbf8b486a8c21335bf14Joe Onorato            }
40775199e3ddcf7886c8ee5fbf8b486a8c21335bf14Joe Onorato        }
4089305647eb61bb60a1f42481a0c0d208dc9bbe965Joe Onorato        synchronized (mLock) {
409e4c7b3f25ee3cb8d3fba4d15a8fbb97bc83d8dd1Joe Onorato            switches[0] = gatherDisableActionsLocked();
41060ee25643e0a7b8841063a4e97b0f18c51807e91Daniel Sandler            switches[1] = mSystemUiVisibility;
411e4c7b3f25ee3cb8d3fba4d15a8fbb97bc83d8dd1Joe Onorato            switches[2] = mMenuVisible ? 1 : 0;
412857fd9b8562c29913e03ed29288bd1802d37dc60Joe Onorato            switches[3] = mImeWindowVis;
413857fd9b8562c29913e03ed29288bd1802d37dc60Joe Onorato            switches[4] = mImeBackDisposition;
414857fd9b8562c29913e03ed29288bd1802d37dc60Joe Onorato            binders.add(mImeToken);
4159305647eb61bb60a1f42481a0c0d208dc9bbe965Joe Onorato        }
4162992ea782fa61780d8e0de7a36a2a84622f8694bJeff Brown        switches[5] = mWindowManager.isHardKeyboardAvailable() ? 1 : 0;
4172992ea782fa61780d8e0de7a36a2a84622f8694bJeff Brown        switches[6] = mWindowManager.isHardKeyboardEnabled() ? 1 : 0;
4182314aab5064ce09f09270e52fa12a38d07464278Joe Onorato    }
419aaba60b281713d45a0f232580302c7b54a7207dfJoe Onorato
4204762c2d75a55e0854bbff2f996748116d4ab1a37Joe Onorato    /**
421f1f259165ffaa4095afbd50fea47ed091cbc14b3Joe Onorato     * The status bar service should call this each time the user brings the panel from
422f1f259165ffaa4095afbd50fea47ed091cbc14b3Joe Onorato     * invisible to visible in order to clear the notification light.
4234762c2d75a55e0854bbff2f996748116d4ab1a37Joe Onorato     */
424f1f259165ffaa4095afbd50fea47ed091cbc14b3Joe Onorato    public void onPanelRevealed() {
4258bc6c5141974dbc36a6fe416853f558921be9f24Joe Onorato        enforceStatusBarService();
4268bc6c5141974dbc36a6fe416853f558921be9f24Joe Onorato
427f1f259165ffaa4095afbd50fea47ed091cbc14b3Joe Onorato        // tell the notification manager to turn off the lights.
428f1f259165ffaa4095afbd50fea47ed091cbc14b3Joe Onorato        mNotificationCallbacks.onPanelRevealed();
4294762c2d75a55e0854bbff2f996748116d4ab1a37Joe Onorato    }
4304762c2d75a55e0854bbff2f996748116d4ab1a37Joe Onorato
431aaba60b281713d45a0f232580302c7b54a7207dfJoe Onorato    public void onNotificationClick(String pkg, String tag, int id) {
4328bc6c5141974dbc36a6fe416853f558921be9f24Joe Onorato        enforceStatusBarService();
4338bc6c5141974dbc36a6fe416853f558921be9f24Joe Onorato
434aaba60b281713d45a0f232580302c7b54a7207dfJoe Onorato        mNotificationCallbacks.onNotificationClick(pkg, tag, id);
435aaba60b281713d45a0f232580302c7b54a7207dfJoe Onorato    }
436aaba60b281713d45a0f232580302c7b54a7207dfJoe Onorato
4379d39d0cb361c5d3bba04a6bacf299be2162a6e92Dianne Hackborn    public void onNotificationError(String pkg, String tag, int id,
4389d39d0cb361c5d3bba04a6bacf299be2162a6e92Dianne Hackborn            int uid, int initialPid, String message) {
4398bc6c5141974dbc36a6fe416853f558921be9f24Joe Onorato        enforceStatusBarService();
4408bc6c5141974dbc36a6fe416853f558921be9f24Joe Onorato
441005847b03b2ebe3eb1a974a8a04ad51bca6636cdJoe Onorato        // WARNING: this will call back into us to do the remove.  Don't hold any locks.
4429d39d0cb361c5d3bba04a6bacf299be2162a6e92Dianne Hackborn        mNotificationCallbacks.onNotificationError(pkg, tag, id, uid, initialPid, message);
443005847b03b2ebe3eb1a974a8a04ad51bca6636cdJoe Onorato    }
444005847b03b2ebe3eb1a974a8a04ad51bca6636cdJoe Onorato
4450f0b11c8719495ce559b93366fe9cd79782d791cDaniel Sandler    public void onNotificationClear(String pkg, String tag, int id) {
4460f0b11c8719495ce559b93366fe9cd79782d791cDaniel Sandler        enforceStatusBarService();
4470f0b11c8719495ce559b93366fe9cd79782d791cDaniel Sandler
4480f0b11c8719495ce559b93366fe9cd79782d791cDaniel Sandler        mNotificationCallbacks.onNotificationClear(pkg, tag, id);
4490f0b11c8719495ce559b93366fe9cd79782d791cDaniel Sandler    }
4500f0b11c8719495ce559b93366fe9cd79782d791cDaniel Sandler
451aaba60b281713d45a0f232580302c7b54a7207dfJoe Onorato    public void onClearAllNotifications() {
4528bc6c5141974dbc36a6fe416853f558921be9f24Joe Onorato        enforceStatusBarService();
4538bc6c5141974dbc36a6fe416853f558921be9f24Joe Onorato
454aaba60b281713d45a0f232580302c7b54a7207dfJoe Onorato        mNotificationCallbacks.onClearAll();
455aaba60b281713d45a0f232580302c7b54a7207dfJoe Onorato    }
456aaba60b281713d45a0f232580302c7b54a7207dfJoe Onorato
45718e69dfc7235f8a4bfe257f9d1c43539049a22ceJoe Onorato    // ================================================================================
45818e69dfc7235f8a4bfe257f9d1c43539049a22ceJoe Onorato    // Callbacks for NotificationManagerService.
45918e69dfc7235f8a4bfe257f9d1c43539049a22ceJoe Onorato    // ================================================================================
46018e69dfc7235f8a4bfe257f9d1c43539049a22ceJoe Onorato    public IBinder addNotification(StatusBarNotification notification) {
46118e69dfc7235f8a4bfe257f9d1c43539049a22ceJoe Onorato        synchronized (mNotifications) {
462a0c56fe93925d20d9c0b830b9664699ce557e78cJoe Onorato            IBinder key = new Binder();
46375199e3ddcf7886c8ee5fbf8b486a8c21335bf14Joe Onorato            mNotifications.put(key, notification);
464e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato            if (mBar != null) {
465e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato                try {
466e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato                    mBar.addNotification(key, notification);
467e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato                } catch (RemoteException ex) {
468e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato                }
469e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato            }
47018e69dfc7235f8a4bfe257f9d1c43539049a22ceJoe Onorato            return key;
47118e69dfc7235f8a4bfe257f9d1c43539049a22ceJoe Onorato        }
4720cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato    }
4732314aab5064ce09f09270e52fa12a38d07464278Joe Onorato
47418e69dfc7235f8a4bfe257f9d1c43539049a22ceJoe Onorato    public void updateNotification(IBinder key, StatusBarNotification notification) {
47518e69dfc7235f8a4bfe257f9d1c43539049a22ceJoe Onorato        synchronized (mNotifications) {
47675199e3ddcf7886c8ee5fbf8b486a8c21335bf14Joe Onorato            if (!mNotifications.containsKey(key)) {
47775199e3ddcf7886c8ee5fbf8b486a8c21335bf14Joe Onorato                throw new IllegalArgumentException("updateNotification key not found: " + key);
47875199e3ddcf7886c8ee5fbf8b486a8c21335bf14Joe Onorato            }
47975199e3ddcf7886c8ee5fbf8b486a8c21335bf14Joe Onorato            mNotifications.put(key, notification);
480e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato            if (mBar != null) {
481e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato                try {
482e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato                    mBar.updateNotification(key, notification);
483e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato                } catch (RemoteException ex) {
484e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato                }
485e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato            }
48618e69dfc7235f8a4bfe257f9d1c43539049a22ceJoe Onorato        }
4879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
4889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4890cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato    public void removeNotification(IBinder key) {
49018e69dfc7235f8a4bfe257f9d1c43539049a22ceJoe Onorato        synchronized (mNotifications) {
49175199e3ddcf7886c8ee5fbf8b486a8c21335bf14Joe Onorato            final StatusBarNotification n = mNotifications.remove(key);
49275199e3ddcf7886c8ee5fbf8b486a8c21335bf14Joe Onorato            if (n == null) {
493fe0806a3b60ff54c7444a51b91353e2299ed1bcaDaniel Sandler                Slog.e(TAG, "removeNotification key not found: " + key);
494fe0806a3b60ff54c7444a51b91353e2299ed1bcaDaniel Sandler                return;
49575199e3ddcf7886c8ee5fbf8b486a8c21335bf14Joe Onorato            }
496e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato            if (mBar != null) {
497e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato                try {
498e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato                    mBar.removeNotification(key);
499e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato                } catch (RemoteException ex) {
500e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato                }
501e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato            }
50218e69dfc7235f8a4bfe257f9d1c43539049a22ceJoe Onorato        }
5039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
5049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
5050cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato    // ================================================================================
5060cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato    // Can be called from any thread
5070cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato    // ================================================================================
5089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
5099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    // lock on mDisableRecords
5109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    void manageDisableListLocked(int what, IBinder token, String pkg) {
5119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if (SPEW) {
512f3f0e053f0cc66249a11639eb67d0cdc2da26dedJoe Onorato            Slog.d(TAG, "manageDisableList what=0x" + Integer.toHexString(what) + " pkg=" + pkg);
5139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
5149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // update the list
5157bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato        final int N = mDisableRecords.size();
5167bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato        DisableRecord tok = null;
5177bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato        int i;
5187bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato        for (i=0; i<N; i++) {
5197bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato            DisableRecord t = mDisableRecords.get(i);
5207bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato            if (t.token == token) {
5217bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato                tok = t;
5227bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato                break;
5239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
5247bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato        }
5257bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato        if (what == 0 || !token.isBinderAlive()) {
5267bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato            if (tok != null) {
5277bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato                mDisableRecords.remove(i);
5287bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato                tok.token.unlinkToDeath(tok, 0);
5297bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato            }
5307bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato        } else {
5317bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato            if (tok == null) {
5327bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato                tok = new DisableRecord();
5337bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato                try {
5347bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato                    token.linkToDeath(tok, 0);
5359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                }
5367bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato                catch (RemoteException ex) {
5377bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato                    return; // give up
5389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                }
5397bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato                mDisableRecords.add(tok);
5409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
5417bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato            tok.what = what;
5427bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato            tok.token = token;
5437bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato            tok.pkg = pkg;
5449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
5459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
5469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
5479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    // lock on mDisableRecords
5489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    int gatherDisableActionsLocked() {
5499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        final int N = mDisableRecords.size();
5509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // gather the new net flags
5519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        int net = 0;
5529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        for (int i=0; i<N; i++) {
5539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            net |= mDisableRecords.get(i).what;
5549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
5559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return net;
5569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
5579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
5589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    // ================================================================================
5599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    // Always called from UI thread
5609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    // ================================================================================
5619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
5629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
5639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                != PackageManager.PERMISSION_GRANTED) {
5659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            pw.println("Permission Denial: can't dump StatusBar from from pid="
5669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                    + Binder.getCallingPid()
5679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                    + ", uid=" + Binder.getCallingUid());
5689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return;
5699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
5700cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato
5710cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato        synchronized (mIcons) {
5720cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato            mIcons.dump(pw);
5730cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato        }
57418e69dfc7235f8a4bfe257f9d1c43539049a22ceJoe Onorato
57518e69dfc7235f8a4bfe257f9d1c43539049a22ceJoe Onorato        synchronized (mNotifications) {
57675199e3ddcf7886c8ee5fbf8b486a8c21335bf14Joe Onorato            int i=0;
57775199e3ddcf7886c8ee5fbf8b486a8c21335bf14Joe Onorato            pw.println("Notification list:");
57875199e3ddcf7886c8ee5fbf8b486a8c21335bf14Joe Onorato            for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
57975199e3ddcf7886c8ee5fbf8b486a8c21335bf14Joe Onorato                pw.printf("  %2d: %s\n", i, e.getValue().toString());
58075199e3ddcf7886c8ee5fbf8b486a8c21335bf14Joe Onorato                i++;
58175199e3ddcf7886c8ee5fbf8b486a8c21335bf14Joe Onorato            }
5829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
58318e69dfc7235f8a4bfe257f9d1c43539049a22ceJoe Onorato
5847bb8eeb90cf55f409a282c1f36ca08aa48c10543Joe Onorato        synchronized (mLock) {
5859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            final int N = mDisableRecords.size();
5869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            pw.println("  mDisableRecords.size=" + N
5879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                    + " mDisabled=0x" + Integer.toHexString(mDisabled));
5889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            for (int i=0; i<N; i++) {
5899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                DisableRecord tok = mDisableRecords.get(i);
5909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                pw.println("    [" + i + "] what=0x" + Integer.toHexString(tok.what)
5919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                                + " pkg=" + tok.pkg + " token=" + tok.token);
5929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
5939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
5949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
5959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
5969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
5979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void onReceive(Context context, Intent intent) {
5989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            String action = intent.getAction();
599f9e0e6bd5e070d4c213e0237fa2fb8d4bb558bcbJoe Onorato            if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
600f9e0e6bd5e070d4c213e0237fa2fb8d4bb558bcbJoe Onorato                    || Intent.ACTION_SCREEN_OFF.equals(action)) {
601f3f0e053f0cc66249a11639eb67d0cdc2da26dedJoe Onorato                collapse();
6029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
6030cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato            /*
6049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            else if (Telephony.Intents.SPN_STRINGS_UPDATED_ACTION.equals(action)) {
6059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                updateNetworkName(intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_SPN, false),
6069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                        intent.getStringExtra(Telephony.Intents.EXTRA_SPN),
6079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                        intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_PLMN, false),
6089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                        intent.getStringExtra(Telephony.Intents.EXTRA_PLMN));
6099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
6109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
6119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                updateResources();
6129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
6130cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato            */
6149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
6159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    };
6169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
618