Migrate from Uid to UserHandle
Fixes WorkProfile storage issues. Bug: 179810781 Test: PeopleSpaceTileTest, PeopleSpaceUtilsTest Change-Id: I9baadc1308fcd5725458bf9dd6e4917e79975dab
This commit is contained in:
@@ -29,6 +29,7 @@ import android.graphics.drawable.Icon;
|
||||
import android.net.Uri;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.os.UserHandle;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -45,7 +46,7 @@ public class PeopleSpaceTile implements Parcelable {
|
||||
private String mId;
|
||||
private CharSequence mUserName;
|
||||
private Icon mUserIcon;
|
||||
private int mUid;
|
||||
private UserHandle mUserHandle;
|
||||
private Uri mContactUri;
|
||||
private String mPackageName;
|
||||
private String mBirthdayText;
|
||||
@@ -64,7 +65,7 @@ public class PeopleSpaceTile implements Parcelable {
|
||||
mUserName = b.mUserName;
|
||||
mUserIcon = b.mUserIcon;
|
||||
mContactUri = b.mContactUri;
|
||||
mUid = b.mUid;
|
||||
mUserHandle = b.mUserHandle;
|
||||
mPackageName = b.mPackageName;
|
||||
mBirthdayText = b.mBirthdayText;
|
||||
mLastInteractionTimestamp = b.mLastInteractionTimestamp;
|
||||
@@ -95,8 +96,8 @@ public class PeopleSpaceTile implements Parcelable {
|
||||
return mContactUri;
|
||||
}
|
||||
|
||||
public int getUid() {
|
||||
return mUid;
|
||||
public UserHandle getUserHandle() {
|
||||
return mUserHandle;
|
||||
}
|
||||
|
||||
public String getPackageName() {
|
||||
@@ -165,7 +166,7 @@ public class PeopleSpaceTile implements Parcelable {
|
||||
Builder builder =
|
||||
new Builder(mId, mUserName.toString(), mUserIcon, mIntent);
|
||||
builder.setContactUri(mContactUri);
|
||||
builder.setUid(mUid);
|
||||
builder.setUserHandle(mUserHandle);
|
||||
builder.setPackageName(mPackageName);
|
||||
builder.setBirthdayText(mBirthdayText);
|
||||
builder.setLastInteractionTimestamp(mLastInteractionTimestamp);
|
||||
@@ -186,7 +187,7 @@ public class PeopleSpaceTile implements Parcelable {
|
||||
private CharSequence mUserName;
|
||||
private Icon mUserIcon;
|
||||
private Uri mContactUri;
|
||||
private int mUid;
|
||||
private UserHandle mUserHandle;
|
||||
private String mPackageName;
|
||||
private String mBirthdayText;
|
||||
private long mLastInteractionTimestamp;
|
||||
@@ -212,7 +213,7 @@ public class PeopleSpaceTile implements Parcelable {
|
||||
mId = info.getId();
|
||||
mUserName = info.getLabel();
|
||||
mUserIcon = convertDrawableToIcon(launcherApps.getShortcutIconDrawable(info, 0));
|
||||
mUid = info.getUserId();
|
||||
mUserHandle = info.getUserHandle();
|
||||
mPackageName = info.getPackage();
|
||||
mContactUri = getContactUri(info);
|
||||
}
|
||||
@@ -222,7 +223,7 @@ public class PeopleSpaceTile implements Parcelable {
|
||||
mId = info.getId();
|
||||
mUserName = info.getLabel();
|
||||
mUserIcon = convertDrawableToIcon(launcherApps.getShortcutIconDrawable(info, 0));
|
||||
mUid = info.getUserId();
|
||||
mUserHandle = info.getUserHandle();
|
||||
mPackageName = info.getPackage();
|
||||
mContactUri = getContactUri(info);
|
||||
mStatuses = channel.getStatuses();
|
||||
@@ -265,9 +266,9 @@ public class PeopleSpaceTile implements Parcelable {
|
||||
return this;
|
||||
}
|
||||
|
||||
/** Sets the associated uid. */
|
||||
public Builder setUid(int uid) {
|
||||
mUid = uid;
|
||||
/** Sets the associated {@code userHandle}. */
|
||||
public Builder setUserHandle(UserHandle userHandle) {
|
||||
mUserHandle = userHandle;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -349,7 +350,7 @@ public class PeopleSpaceTile implements Parcelable {
|
||||
mUserName = in.readCharSequence();
|
||||
mUserIcon = in.readParcelable(Icon.class.getClassLoader());
|
||||
mContactUri = in.readParcelable(Uri.class.getClassLoader());
|
||||
mUid = in.readInt();
|
||||
mUserHandle = in.readParcelable(UserHandle.class.getClassLoader());
|
||||
mPackageName = in.readString();
|
||||
mBirthdayText = in.readString();
|
||||
mLastInteractionTimestamp = in.readLong();
|
||||
@@ -375,7 +376,7 @@ public class PeopleSpaceTile implements Parcelable {
|
||||
dest.writeCharSequence(mUserName);
|
||||
dest.writeParcelable(mUserIcon, flags);
|
||||
dest.writeParcelable(mContactUri, flags);
|
||||
dest.writeInt(mUid);
|
||||
dest.writeParcelable(mUserHandle, flags);
|
||||
dest.writeString(mPackageName);
|
||||
dest.writeString(mBirthdayText);
|
||||
dest.writeLong(mLastInteractionTimestamp);
|
||||
|
||||
@@ -37,6 +37,7 @@ import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.net.Uri;
|
||||
import android.os.Parcel;
|
||||
import android.os.UserHandle;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.filters.SmallTest;
|
||||
@@ -124,13 +125,13 @@ public class PeopleSpaceTileTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUid() {
|
||||
public void testUserHandle() {
|
||||
PeopleSpaceTile tile = new PeopleSpaceTile
|
||||
.Builder(new ShortcutInfo.Builder(mContext, "123").build(), mLauncherApps)
|
||||
.setUid(42)
|
||||
.setUserHandle(new UserHandle(0))
|
||||
.build();
|
||||
|
||||
assertThat(tile.getUid()).isEqualTo(42);
|
||||
assertThat(tile.getUserHandle()).isEqualTo(new UserHandle(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -227,7 +228,7 @@ public class PeopleSpaceTileTest {
|
||||
.setUserName("name")
|
||||
.setUserIcon(mIcon)
|
||||
.setContactUri(Uri.parse("contact"))
|
||||
.setUid(42)
|
||||
.setUserHandle(new UserHandle(1))
|
||||
.setPackageName("package.name")
|
||||
.setLastInteractionTimestamp(7L)
|
||||
.setIsImportantConversation(true)
|
||||
@@ -246,7 +247,7 @@ public class PeopleSpaceTileTest {
|
||||
assertThat(readTile.getUserName()).isEqualTo(tile.getUserName());
|
||||
assertThat(readTile.getUserIcon().toString()).isEqualTo(tile.getUserIcon().toString());
|
||||
assertThat(readTile.getContactUri()).isEqualTo(tile.getContactUri());
|
||||
assertThat(readTile.getUid()).isEqualTo(tile.getUid());
|
||||
assertThat(readTile.getUserHandle()).isEqualTo(tile.getUserHandle());
|
||||
assertThat(readTile.getPackageName()).isEqualTo(tile.getPackageName());
|
||||
assertThat(readTile.getLastInteractionTimestamp()).isEqualTo(
|
||||
tile.getLastInteractionTimestamp());
|
||||
|
||||
@@ -19,8 +19,6 @@ package com.android.systemui.people;
|
||||
import static android.appwidget.AppWidgetManager.EXTRA_APPWIDGET_ID;
|
||||
import static android.appwidget.AppWidgetManager.INVALID_APPWIDGET_ID;
|
||||
|
||||
import static com.android.systemui.people.PeopleSpaceUtils.getUserHandle;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.INotificationManager;
|
||||
import android.app.people.IPeopleManager;
|
||||
@@ -155,7 +153,7 @@ public class PeopleSpaceActivity extends Activity {
|
||||
if (DEBUG) Log.d(TAG, "Caching shortcut for PeopleTile: " + tile.getId());
|
||||
mLauncherApps.cacheShortcuts(tile.getPackageName(),
|
||||
Collections.singletonList(tile.getId()),
|
||||
getUserHandle(tile), LauncherApps.FLAG_CACHE_PEOPLE_TILE_SHORTCUTS);
|
||||
tile.getUserHandle(), LauncherApps.FLAG_CACHE_PEOPLE_TILE_SHORTCUTS);
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, "Exception caching shortcut:" + e);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import android.content.Context;
|
||||
import android.content.pm.LauncherApps;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.os.UserHandle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -82,7 +81,7 @@ public class PeopleSpaceTileView extends LinearLayout {
|
||||
public void setOnClickListener(LauncherApps launcherApps, PeopleSpaceTile tile) {
|
||||
mTileView.setOnClickListener(v ->
|
||||
launcherApps.startShortcut(tile.getPackageName(), tile.getId(), null, null,
|
||||
UserHandle.getUserHandleForUid(tile.getUid())));
|
||||
tile.getUserHandle()));
|
||||
}
|
||||
|
||||
/** Sets the click listener of the tile directly. */
|
||||
|
||||
@@ -55,7 +55,6 @@ import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.os.ServiceManager;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.ContactsContract;
|
||||
import android.provider.Settings;
|
||||
import android.service.notification.ConversationChannelWrapper;
|
||||
@@ -160,7 +159,6 @@ public class PeopleSpaceUtils {
|
||||
List<ConversationChannelWrapper> conversations =
|
||||
notificationManager.getConversations(
|
||||
false).getList();
|
||||
|
||||
// Add priority conversations to tiles list.
|
||||
Stream<ShortcutInfo> priorityConversations = conversations.stream()
|
||||
.filter(c -> c.getNotificationChannel() != null
|
||||
@@ -252,7 +250,11 @@ public class PeopleSpaceUtils {
|
||||
}
|
||||
|
||||
// If tile is null, we need to retrieve from persisted storage.
|
||||
if (DEBUG) Log.d(TAG, "Retrieving from storage after reboots");
|
||||
if (DEBUG) {
|
||||
Log.d(TAG,
|
||||
"Retrieving from storage after reboots: " + shortcutId + " user: " + userId
|
||||
+ " pkg: " + pkg);
|
||||
}
|
||||
LauncherApps launcherApps = context.getSystemService(LauncherApps.class);
|
||||
ConversationChannel channel = peopleManager.getConversation(pkg, userId, shortcutId);
|
||||
if (channel == null) {
|
||||
@@ -384,7 +386,7 @@ public class PeopleSpaceUtils {
|
||||
PeopleSpaceTile tile, Map<String, NotificationEntry> visibleNotifications) {
|
||||
String shortcutId = tile.getId();
|
||||
String packageName = tile.getPackageName();
|
||||
int userId = UserHandle.getUserHandleForUid(tile.getUid()).getIdentifier();
|
||||
int userId = getUserId(tile);
|
||||
String key = getKey(shortcutId, packageName, userId);
|
||||
if (!visibleNotifications.containsKey(key)) {
|
||||
if (DEBUG) Log.d(TAG, "No existing notifications for key:" + key);
|
||||
@@ -641,7 +643,8 @@ public class PeopleSpaceUtils {
|
||||
activityIntent.putExtra(PeopleSpaceWidgetProvider.EXTRA_TILE_ID, tile.getId());
|
||||
activityIntent.putExtra(
|
||||
PeopleSpaceWidgetProvider.EXTRA_PACKAGE_NAME, tile.getPackageName());
|
||||
activityIntent.putExtra(PeopleSpaceWidgetProvider.EXTRA_UID, tile.getUid());
|
||||
activityIntent.putExtra(PeopleSpaceWidgetProvider.EXTRA_USER_HANDLE,
|
||||
tile.getUserHandle());
|
||||
views.setOnClickPendingIntent(R.id.item, PendingIntent.getActivity(
|
||||
context,
|
||||
appWidgetId,
|
||||
@@ -788,7 +791,6 @@ public class PeopleSpaceUtils {
|
||||
Log.i(TAG, "ConversationChannel is null");
|
||||
return null;
|
||||
}
|
||||
|
||||
PeopleSpaceTile tile = new PeopleSpaceTile.Builder(channel, launcherApps).build();
|
||||
if (!PeopleSpaceUtils.shouldKeepConversation(tile)) {
|
||||
Log.i(TAG, "PeopleSpaceTile is not valid");
|
||||
@@ -1069,11 +1071,6 @@ public class PeopleSpaceUtils {
|
||||
|
||||
/** Returns the userId associated with a {@link PeopleSpaceTile} */
|
||||
public static int getUserId(PeopleSpaceTile tile) {
|
||||
return getUserHandle(tile).getIdentifier();
|
||||
}
|
||||
|
||||
/** Returns the {@link UserHandle} associated with a {@link PeopleSpaceTile} */
|
||||
public static UserHandle getUserHandle(PeopleSpaceTile tile) {
|
||||
return UserHandle.getUserHandleForUid(tile.getUid());
|
||||
return tile.getUserHandle().getIdentifier();
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,8 @@ public class LaunchConversationActivity extends Activity {
|
||||
Intent intent = getIntent();
|
||||
String tileId = intent.getStringExtra(PeopleSpaceWidgetProvider.EXTRA_TILE_ID);
|
||||
String packageName = intent.getStringExtra(PeopleSpaceWidgetProvider.EXTRA_PACKAGE_NAME);
|
||||
int uid = intent.getIntExtra(PeopleSpaceWidgetProvider.EXTRA_UID, 0);
|
||||
UserHandle userHandle = intent.getParcelableExtra(
|
||||
PeopleSpaceWidgetProvider.EXTRA_USER_HANDLE);
|
||||
|
||||
if (tileId != null && !tileId.isEmpty()) {
|
||||
if (DEBUG) {
|
||||
@@ -52,7 +53,7 @@ public class LaunchConversationActivity extends Activity {
|
||||
LauncherApps launcherApps =
|
||||
getApplicationContext().getSystemService(LauncherApps.class);
|
||||
launcherApps.startShortcut(
|
||||
packageName, tileId, null, null, UserHandle.getUserHandleForUid(uid));
|
||||
packageName, tileId, null, null, userHandle);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Exception starting shortcut:" + e);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public class PeopleSpaceWidgetProvider extends AppWidgetProvider {
|
||||
|
||||
public static final String EXTRA_TILE_ID = "extra_tile_id";
|
||||
public static final String EXTRA_PACKAGE_NAME = "extra_package_name";
|
||||
public static final String EXTRA_UID = "extra_uid";
|
||||
public static final String EXTRA_USER_HANDLE = "extra_user_handle";
|
||||
|
||||
public UiEventLogger mUiEventLogger = new UiEventLoggerImpl();
|
||||
|
||||
|
||||
@@ -123,7 +123,8 @@ public class PeopleSpaceWidgetRemoteViewsFactory implements RemoteViewsService.R
|
||||
fillInIntent.putExtra(PeopleSpaceWidgetProvider.EXTRA_TILE_ID, tile.getId());
|
||||
fillInIntent.putExtra(
|
||||
PeopleSpaceWidgetProvider.EXTRA_PACKAGE_NAME, tile.getPackageName());
|
||||
fillInIntent.putExtra(PeopleSpaceWidgetProvider.EXTRA_UID, tile.getUid());
|
||||
fillInIntent.putExtra(PeopleSpaceWidgetProvider.EXTRA_USER_HANDLE,
|
||||
tile.getUserHandle());
|
||||
personView.setOnClickFillInIntent(R.id.item, fillInIntent);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Couldn't retrieve shortcut information", e);
|
||||
|
||||
@@ -464,7 +464,7 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase {
|
||||
new PeopleSpaceTile
|
||||
.Builder(SHORTCUT_ID_1, "userName", ICON, new Intent())
|
||||
.setPackageName(PACKAGE_NAME)
|
||||
.setUid(0)
|
||||
.setUserHandle(new UserHandle(0))
|
||||
.build();
|
||||
PeopleSpaceTile actual = PeopleSpaceUtils
|
||||
.augmentTileFromNotification(mContext, tile, sbn);
|
||||
@@ -482,7 +482,7 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase {
|
||||
new PeopleSpaceTile
|
||||
.Builder(SHORTCUT_ID_3, "userName", ICON, new Intent())
|
||||
.setPackageName(PACKAGE_NAME)
|
||||
.setUid(0)
|
||||
.setUserHandle(new UserHandle(0))
|
||||
.build();
|
||||
PeopleSpaceTile actual = PeopleSpaceUtils
|
||||
.augmentTileFromNotification(mContext, tile, sbn);
|
||||
@@ -496,7 +496,7 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase {
|
||||
new PeopleSpaceTile
|
||||
.Builder(SHORTCUT_ID_1, "userName", ICON, new Intent())
|
||||
.setPackageName(PACKAGE_NAME)
|
||||
.setUid(0)
|
||||
.setUserHandle(new UserHandle(0))
|
||||
.build();
|
||||
PeopleSpaceTile actual = PeopleSpaceUtils
|
||||
.augmentTileFromVisibleNotifications(mContext, tile,
|
||||
@@ -511,7 +511,7 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase {
|
||||
new PeopleSpaceTile
|
||||
.Builder(SHORTCUT_ID_4, "userName", ICON, new Intent())
|
||||
.setPackageName(PACKAGE_NAME)
|
||||
.setUid(0)
|
||||
.setUserHandle(new UserHandle(0))
|
||||
.build();
|
||||
PeopleSpaceTile actual = PeopleSpaceUtils
|
||||
.augmentTileFromVisibleNotifications(mContext, tile,
|
||||
@@ -526,7 +526,7 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase {
|
||||
new PeopleSpaceTile
|
||||
.Builder(SHORTCUT_ID_1, "userName", ICON, new Intent())
|
||||
.setPackageName(PACKAGE_NAME)
|
||||
.setUid(0)
|
||||
.setUserHandle(new UserHandle(0))
|
||||
.build();
|
||||
List<PeopleSpaceTile> actualList = PeopleSpaceUtils
|
||||
.augmentTilesFromVisibleNotifications(
|
||||
@@ -545,13 +545,13 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase {
|
||||
new PeopleSpaceTile
|
||||
.Builder(SHORTCUT_ID_1, "userName", ICON, new Intent())
|
||||
.setPackageName(PACKAGE_NAME)
|
||||
.setUid(1)
|
||||
.setUserHandle(new UserHandle(0))
|
||||
.build();
|
||||
PeopleSpaceTile tile2 =
|
||||
new PeopleSpaceTile
|
||||
.Builder(SHORTCUT_ID_2, "userName2", ICON, new Intent())
|
||||
.setPackageName(PACKAGE_NAME)
|
||||
.setUid(0)
|
||||
.setUserHandle(new UserHandle(0))
|
||||
.build();
|
||||
List<PeopleSpaceTile> actualList = PeopleSpaceUtils
|
||||
.augmentTilesFromVisibleNotifications(mContext, List.of(tile1, tile2),
|
||||
|
||||
@@ -109,7 +109,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase {
|
||||
new PeopleSpaceTile
|
||||
.Builder(SHORTCUT_ID, "username", ICON, new Intent())
|
||||
.setPackageName(TEST_PACKAGE_A)
|
||||
.setUid(0)
|
||||
.setUserHandle(new UserHandle(1))
|
||||
.setNotificationKey(NOTIFICATION_KEY + "1")
|
||||
.setNotificationContent(NOTIFICATION_CONTENT)
|
||||
.setNotificationDataUri(URI)
|
||||
|
||||
Reference in New Issue
Block a user