Skip to content

Commit 2289167

Browse files
dsandlerAndroid (Google) Code Review
authored andcommitted
Merge "Multiuser support for notifications, take 1." into jb-mr1-dev
2 parents 2b197db + b9301c3 commit 2289167

File tree

6 files changed

+105
-9
lines changed

6 files changed

+105
-9
lines changed

core/java/com/android/internal/statusbar/StatusBarNotification.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import android.app.Notification;
2020
import android.os.Parcel;
2121
import android.os.Parcelable;
22+
import android.os.UserId;
2223
import android.widget.RemoteViews;
2324

2425

@@ -132,6 +133,11 @@ public boolean isClearable() {
132133
return ((notification.flags & Notification.FLAG_ONGOING_EVENT) == 0)
133134
&& ((notification.flags & Notification.FLAG_NO_CLEAR) == 0);
134135
}
136+
137+
/** Returns a userHandle for the instance of the app that posted this notification. */
138+
public int getUserId() {
139+
return UserId.getUserId(this.uid);
140+
}
135141
}
136142

137143

packages/SystemUI/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
1616
<uses-permission android:name="android.permission.REMOTE_AUDIO_PLAYBACK" />
1717

18+
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
19+
1820
<!-- Networking and telephony -->
1921
<uses-permission android:name="android.permission.BLUETOOTH" />
2022
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

packages/SystemUI/res/layout/status_bar_expanded_header.xml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,24 @@
6565
android:layout_weight="1"
6666
/>
6767

68+
<TextView
69+
android:id="@+id/header_debug_info"
70+
android:visibility="invisible"
71+
android:layout_width="wrap_content"
72+
android:layout_height="wrap_content"
73+
android:layout_gravity="center_vertical"
74+
android:fontFamily="sans-serif-condensed"
75+
android:textSize="11dp"
76+
android:textStyle="bold"
77+
android:textColor="#00A040"
78+
android:padding="2dp"
79+
/>
80+
6881
<ImageView android:id="@+id/clear_all_button"
6982
android:layout_width="48dp"
7083
android:layout_height="48dp"
7184
android:scaleType="center"
7285
android:src="@drawable/ic_notify_clear"
7386
android:contentDescription="@string/accessibility_clear_all"
74-
/>
75-
</LinearLayout>
87+
/>
88+
</LinearLayout>

packages/SystemUI/res/layout/status_bar_notification_row.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,17 @@
4949
android:background="@drawable/bottom_divider_glow"
5050
/>
5151

52+
<TextView
53+
android:id="@+id/debug_info"
54+
android:visibility="invisible"
55+
android:layout_width="wrap_content"
56+
android:layout_height="wrap_content"
57+
android:layout_gravity="bottom|right"
58+
android:fontFamily="sans-serif-condensed"
59+
android:textSize="9dp"
60+
android:textStyle="bold"
61+
android:textColor="#00A040"
62+
android:padding="2dp"
63+
/>
64+
5265
</FrameLayout>

packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@
3434
import android.app.KeyguardManager;
3535
import android.app.PendingIntent;
3636
import android.app.TaskStackBuilder;
37+
import android.content.BroadcastReceiver;
3738
import android.content.Context;
3839
import android.content.Intent;
40+
import android.content.IntentFilter;
3941
import android.content.pm.ApplicationInfo;
4042
import android.content.pm.PackageManager.NameNotFoundException;
4143
import android.database.ContentObserver;
@@ -47,6 +49,7 @@
4749
import android.os.Message;
4850
import android.os.RemoteException;
4951
import android.os.ServiceManager;
52+
import android.os.UserId;
5053
import android.provider.Settings;
5154
import android.text.TextUtils;
5255
import android.util.Log;
@@ -65,13 +68,15 @@
6568
import android.widget.LinearLayout;
6669
import android.widget.PopupMenu;
6770
import android.widget.RemoteViews;
71+
import android.widget.TextView;
6872

6973
import java.util.ArrayList;
7074

7175
public abstract class BaseStatusBar extends SystemUI implements
7276
CommandQueue.Callbacks, RecentsPanelView.OnRecentsPanelVisibilityChangedListener {
7377
static final String TAG = "StatusBar";
7478
private static final boolean DEBUG = false;
79+
public static final boolean MULTIUSER_DEBUG = false;
7580

7681
protected static final int MSG_OPEN_RECENTS_PANEL = 1020;
7782
protected static final int MSG_CLOSE_RECENTS_PANEL = 1021;
@@ -112,6 +117,8 @@ public abstract class BaseStatusBar extends SystemUI implements
112117

113118
protected PopupMenu mNotificationBlamePopup;
114119

120+
protected int mCurrentUserId = 0;
121+
115122
// UI-specific methods
116123

117124
/**
@@ -252,6 +259,40 @@ public void start() {
252259
switches[3]
253260
));
254261
}
262+
263+
// XXX: this is currently broken and will always return 0, but should start working at some point
264+
try {
265+
mCurrentUserId = ActivityManagerNative.getDefault().getCurrentUser().id;
266+
} catch (RemoteException e) {
267+
Log.v(TAG, "Couldn't get current user ID; guessing it's 0", e);
268+
}
269+
270+
IntentFilter filter = new IntentFilter();
271+
filter.addAction(Intent.ACTION_USER_SWITCHED);
272+
mContext.registerReceiver(new BroadcastReceiver() {
273+
@Override
274+
public void onReceive(Context context, Intent intent) {
275+
String action = intent.getAction();
276+
if (Intent.ACTION_USER_SWITCHED.equals(action)) {
277+
mCurrentUserId = intent.getIntExtra(Intent.EXTRA_USERID, -1);
278+
if (true) Slog.v(TAG, "userId " + mCurrentUserId + " is in the house");
279+
userSwitched(mCurrentUserId);
280+
}
281+
}}, filter);
282+
}
283+
284+
public void userSwitched(int newUserId) {
285+
// should be overridden
286+
}
287+
288+
public boolean notificationIsForCurrentUser(StatusBarNotification n) {
289+
final int thisUserId = mCurrentUserId;
290+
final int notificationUserId = n.getUserId();
291+
if (DEBUG && MULTIUSER_DEBUG) {
292+
Slog.v(TAG, String.format("%s: current userid: %d, notification userid: %d",
293+
n, thisUserId, notificationUserId));
294+
}
295+
return thisUserId == notificationUserId;
255296
}
256297

257298
protected View updateNotificationVetoButton(View row, StatusBarNotification n) {
@@ -604,6 +645,14 @@ protected boolean inflateViews(NotificationData.Entry entry, ViewGroup parent)
604645
applyLegacyRowBackground(sbn, content);
605646

606647
row.setTag(R.id.expandable_tag, Boolean.valueOf(large != null));
648+
649+
if (MULTIUSER_DEBUG) {
650+
TextView debug = (TextView) row.findViewById(R.id.debug_info);
651+
if (debug != null) {
652+
debug.setVisibility(View.VISIBLE);
653+
debug.setText("U " + entry.notification.getUserId());
654+
}
655+
}
607656
entry.row = row;
608657
entry.content = content;
609658
entry.expanded = expandedOneU;

packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ public class PhoneStatusBar extends BaseStatusBar {
174174
int mNotificationPanelMarginBottomPx, mNotificationPanelMarginPx;
175175
int mNotificationPanelMinHeight;
176176
boolean mNotificationPanelIsFullScreenWidth;
177+
TextView mNotificationPanelDebugText;
177178

178179
// settings
179180
PanelView mSettingsPanel;
@@ -343,6 +344,10 @@ public boolean onTouch(View v, MotionEvent event) {
343344
mIntruderAlertView.setVisibility(View.GONE);
344345
mIntruderAlertView.setBar(this);
345346
}
347+
if (MULTIUSER_DEBUG) {
348+
mNotificationPanelDebugText = (TextView) mNotificationPanel.findViewById(R.id.header_debug_info);
349+
mNotificationPanelDebugText.setVisibility(View.VISIBLE);
350+
}
346351

347352
updateShowSearchHoldoff();
348353

@@ -806,9 +811,9 @@ private void loadNotificationShade() {
806811
// If the device hasn't been through Setup, we only show system notifications
807812
for (int i=0; i<N; i++) {
808813
Entry ent = mNotificationData.get(N-i-1);
809-
if (provisioned || showNotificationEvenIfUnprovisioned(ent.notification)) {
810-
toShow.add(ent.row);
811-
}
814+
if (!(provisioned || showNotificationEvenIfUnprovisioned(ent.notification))) continue;
815+
if (!notificationIsForCurrentUser(ent.notification)) continue;
816+
toShow.add(ent.row);
812817
}
813818

814819
ArrayList<View> toRemove = new ArrayList<View>();
@@ -854,10 +859,10 @@ protected void updateNotificationIcons() {
854859
// If the device hasn't been through Setup, we only show system notifications
855860
for (int i=0; i<N; i++) {
856861
Entry ent = mNotificationData.get(N-i-1);
857-
if ((provisioned && ent.notification.score >= HIDE_ICONS_BELOW_SCORE)
858-
|| showNotificationEvenIfUnprovisioned(ent.notification)) {
859-
toShow.add(ent.icon);
860-
}
862+
if (!((provisioned && ent.notification.score >= HIDE_ICONS_BELOW_SCORE)
863+
|| showNotificationEvenIfUnprovisioned(ent.notification))) continue;
864+
if (!notificationIsForCurrentUser(ent.notification)) continue;
865+
toShow.add(ent.icon);
861866
}
862867

863868
ArrayList<View> toRemove = new ArrayList<View>();
@@ -1789,6 +1794,7 @@ public void onClick(View v) {
17891794

17901795
private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
17911796
public void onReceive(Context context, Intent intent) {
1797+
Slog.v(TAG, "onReceive: " + intent);
17921798
String action = intent.getAction();
17931799
if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) {
17941800
int flags = CommandQueue.FLAG_EXCLUDE_NONE;
@@ -1812,6 +1818,13 @@ else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
18121818
}
18131819
};
18141820

1821+
@Override
1822+
public void userSwitched(int newUserId) {
1823+
if (MULTIUSER_DEBUG) mNotificationPanelDebugText.setText("USER " + newUserId);
1824+
animateCollapse();
1825+
updateNotificationIcons();
1826+
}
1827+
18151828
private void setIntruderAlertVisibility(boolean vis) {
18161829
if (!ENABLE_INTRUDERS) return;
18171830
if (DEBUG) {

0 commit comments

Comments
 (0)