Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b9301c3a authored by Daniel Sandler's avatar Daniel Sandler
Browse files

Multiuser support for notifications, take 1.

Notifications for background users are hidden from the
panel and status bar.

Still need to add a concept of "any user" notifications (for
things coming from the system) and notification visibility
controls (for access to icons + possibly masked text of
a background user's notifications).

Change-Id: Iba121f35a6c25c2e1c44db029d776a5a59a6a008
parent 978f853d
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.internal.statusbar;
import android.app.Notification;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.UserId;
import android.widget.RemoteViews;


@@ -132,6 +133,11 @@ public class StatusBarNotification implements Parcelable {
        return ((notification.flags & Notification.FLAG_ONGOING_EVENT) == 0)
                && ((notification.flags & Notification.FLAG_NO_CLEAR) == 0);
    }

    /** Returns a userHandle for the instance of the app that posted this notification. */
    public int getUserId() {
        return UserId.getUserId(this.uid);
    }
}

+2 −0
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@
    <uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
    <uses-permission android:name="android.permission.REMOTE_AUDIO_PLAYBACK" />

    <uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />

    <!-- Networking and telephony -->
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
+15 −2
Original line number Diff line number Diff line
@@ -65,6 +65,19 @@
        android:layout_weight="1"
        />

    <TextView
        android:id="@+id/header_debug_info"
        android:visibility="invisible"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:fontFamily="sans-serif-condensed"
        android:textSize="11dp"
        android:textStyle="bold"
        android:textColor="#00A040"
        android:padding="2dp"
        />
    
    <ImageView android:id="@+id/clear_all_button"
        android:layout_width="48dp"
        android:layout_height="48dp"
+13 −0
Original line number Diff line number Diff line
@@ -49,4 +49,17 @@
        android:background="@drawable/bottom_divider_glow"
        />

    <TextView
        android:id="@+id/debug_info"
        android:visibility="invisible"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|right"
        android:fontFamily="sans-serif-condensed"
        android:textSize="9dp"
        android:textStyle="bold"
        android:textColor="#00A040"
        android:padding="2dp"
        />

</FrameLayout>
+49 −0
Original line number Diff line number Diff line
@@ -34,8 +34,10 @@ import android.app.ActivityManagerNative;
import android.app.KeyguardManager;
import android.app.PendingIntent;
import android.app.TaskStackBuilder;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.database.ContentObserver;
@@ -47,6 +49,7 @@ import android.os.IBinder;
import android.os.Message;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserId;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
@@ -65,6 +68,7 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupMenu;
import android.widget.RemoteViews;
import android.widget.TextView;

import java.util.ArrayList;

@@ -72,6 +76,7 @@ public abstract class BaseStatusBar extends SystemUI implements
    CommandQueue.Callbacks, RecentsPanelView.OnRecentsPanelVisibilityChangedListener {
    static final String TAG = "StatusBar";
    private static final boolean DEBUG = false;
    public static final boolean MULTIUSER_DEBUG = false;

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

    protected PopupMenu mNotificationBlamePopup;

    protected int mCurrentUserId = 0;

    // UI-specific methods

    /**
@@ -252,6 +259,40 @@ public abstract class BaseStatusBar extends SystemUI implements
                   switches[3]
                   ));
        }

        // XXX: this is currently broken and will always return 0, but should start working at some point
        try {
            mCurrentUserId = ActivityManagerNative.getDefault().getCurrentUser().id;
        } catch (RemoteException e) {
            Log.v(TAG, "Couldn't get current user ID; guessing it's 0", e);
        }

        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_USER_SWITCHED);
        mContext.registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                String action = intent.getAction();
                if (Intent.ACTION_USER_SWITCHED.equals(action)) {
                    mCurrentUserId = intent.getIntExtra(Intent.EXTRA_USERID, -1);
                    if (true) Slog.v(TAG, "userId " + mCurrentUserId + " is in the house");
                    userSwitched(mCurrentUserId);
                }
            }}, filter);
    }

    public void userSwitched(int newUserId) {
        // should be overridden
    }

    public boolean notificationIsForCurrentUser(StatusBarNotification n) {
        final int thisUserId = mCurrentUserId;
        final int notificationUserId = n.getUserId();
        if (DEBUG && MULTIUSER_DEBUG) {
            Slog.v(TAG, String.format("%s: current userid: %d, notification userid: %d",
                    n, thisUserId, notificationUserId));
        }
        return thisUserId == notificationUserId;
    }

    protected View updateNotificationVetoButton(View row, StatusBarNotification n) {
@@ -604,6 +645,14 @@ public abstract class BaseStatusBar extends SystemUI implements
        applyLegacyRowBackground(sbn, content);

        row.setTag(R.id.expandable_tag, Boolean.valueOf(large != null));

        if (MULTIUSER_DEBUG) {
            TextView debug = (TextView) row.findViewById(R.id.debug_info);
            if (debug != null) {
                debug.setVisibility(View.VISIBLE);
                debug.setText("U " + entry.notification.getUserId());
            }
        }
        entry.row = row;
        entry.content = content;
        entry.expanded = expandedOneU;
Loading