Merge "Persist Theme name instead of ID for ShortcutInfo" into sc-dev am: 41e7f367ed

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14783472

Change-Id: Ib9cbb8c121483602fd6a1d28f0ab63047a36a2a3
This commit is contained in:
Issei Suzuki
2021-06-16 15:17:24 +00:00
committed by Automerger Merge Worker
11 changed files with 81 additions and 58 deletions

View File

@@ -419,7 +419,7 @@ public class ActivityOptions {
private IBinder mLaunchCookie;
private IRemoteTransition mRemoteTransition;
private boolean mOverrideTaskTransition;
private int mSplashScreenThemeResId;
private String mSplashScreenThemeResName;
@SplashScreen.SplashScreenStyle
private int mSplashScreenStyle;
private boolean mRemoveWithTaskOrganizer;
@@ -1174,7 +1174,7 @@ public class ActivityOptions {
mRemoteTransition = IRemoteTransition.Stub.asInterface(opts.getBinder(
KEY_REMOTE_TRANSITION));
mOverrideTaskTransition = opts.getBoolean(KEY_OVERRIDE_TASK_TRANSITION);
mSplashScreenThemeResId = opts.getInt(KEY_SPLASH_SCREEN_THEME);
mSplashScreenThemeResName = opts.getString(KEY_SPLASH_SCREEN_THEME);
mRemoveWithTaskOrganizer = opts.getBoolean(KEY_REMOVE_WITH_TASK_ORGANIZER);
mLaunchedFromBubble = opts.getBoolean(KEY_LAUNCHED_FROM_BUBBLE);
mTransientLaunch = opts.getBoolean(KEY_TRANSIENT_LAUNCH);
@@ -1368,8 +1368,9 @@ public class ActivityOptions {
* Gets whether the activity want to be launched as other theme for the splash screen.
* @hide
*/
public int getSplashScreenThemeResId() {
return mSplashScreenThemeResId;
@Nullable
public String getSplashScreenThemeResName() {
return mSplashScreenThemeResName;
}
/**
@@ -1945,8 +1946,8 @@ public class ActivityOptions {
if (mOverrideTaskTransition) {
b.putBoolean(KEY_OVERRIDE_TASK_TRANSITION, mOverrideTaskTransition);
}
if (mSplashScreenThemeResId != 0) {
b.putInt(KEY_SPLASH_SCREEN_THEME, mSplashScreenThemeResId);
if (mSplashScreenThemeResName != null && !mSplashScreenThemeResName.isEmpty()) {
b.putString(KEY_SPLASH_SCREEN_THEME, mSplashScreenThemeResName);
}
if (mRemoveWithTaskOrganizer) {
b.putBoolean(KEY_REMOVE_WITH_TASK_ORGANIZER, mRemoveWithTaskOrganizer);

View File

@@ -423,7 +423,7 @@ public class AppSearchShortcutInfo extends GenericDocument {
shortLabelResName, longLabel, longLabelResId, longLabelResName, disabledMessage,
disabledMessageResId, disabledMessageResName, categoriesSet, intents, rank, extras,
getCreationTimestampMillis(), flags, iconResId, iconResName, bitmapPath, iconUri,
disabledReason, persons, locusId, 0);
disabledReason, persons, locusId, null);
si.setImplicitRank(implicitRank);
if ((implicitRank & ShortcutInfo.RANK_CHANGED_BIT) != 0) {
si.setRankChanged();

View File

@@ -449,7 +449,7 @@ public final class ShortcutInfo implements Parcelable {
private int mDisabledReason;
private int mStartingThemeResId;
@Nullable private String mStartingThemeResName;
private ShortcutInfo(Builder b) {
mUserId = b.mContext.getUserId();
@@ -478,8 +478,9 @@ public final class ShortcutInfo implements Parcelable {
mExtras = b.mExtras;
mLocusId = b.mLocusId;
mStartingThemeResName = b.mStartingThemeResId != 0
? b.mContext.getResources().getResourceName(b.mStartingThemeResId) : null;
updateTimestamp();
mStartingThemeResId = b.mStartingThemeResId;
}
/**
@@ -626,7 +627,7 @@ public final class ShortcutInfo implements Parcelable {
// Set this bit.
mFlags |= FLAG_KEY_FIELDS_ONLY;
}
mStartingThemeResId = source.mStartingThemeResId;
mStartingThemeResName = source.mStartingThemeResName;
}
/**
@@ -950,8 +951,8 @@ public final class ShortcutInfo implements Parcelable {
if (source.mLocusId != null) {
mLocusId = source.mLocusId;
}
if (source.mStartingThemeResId != 0) {
mStartingThemeResId = source.mStartingThemeResId;
if (source.mStartingThemeResName != null && !source.mStartingThemeResName.isEmpty()) {
mStartingThemeResName = source.mStartingThemeResName;
}
}
@@ -1454,11 +1455,12 @@ public final class ShortcutInfo implements Parcelable {
}
/**
* Returns the theme resource id used for the splash screen.
* Returns the theme resource name used for the splash screen.
* @hide
*/
public int getStartingThemeResId() {
return mStartingThemeResId;
@Nullable
public String getStartingThemeResName() {
return mStartingThemeResName;
}
/** @hide -- old signature, the internal code still uses it. */
@@ -2182,7 +2184,7 @@ public final class ShortcutInfo implements Parcelable {
mPersons = source.readParcelableArray(cl, Person.class);
mLocusId = source.readParcelable(cl);
mIconUri = source.readString8();
mStartingThemeResId = source.readInt();
mStartingThemeResName = source.readString8();
}
@Override
@@ -2234,7 +2236,7 @@ public final class ShortcutInfo implements Parcelable {
dest.writeParcelableArray(mPersons, flags);
dest.writeParcelable(mLocusId, flags);
dest.writeString8(mIconUri);
dest.writeInt(mStartingThemeResId);
dest.writeString8(mStartingThemeResName);
}
public static final @NonNull Creator<ShortcutInfo> CREATOR =
@@ -2391,10 +2393,10 @@ public final class ShortcutInfo implements Parcelable {
sb.append("disabledReason=");
sb.append(getDisabledReasonDebugString(mDisabledReason));
if (mStartingThemeResId != 0) {
if (mStartingThemeResName != null && !mStartingThemeResName.isEmpty()) {
addIndentOrComma(sb, indent);
sb.append("SplashScreenThemeResId=");
sb.append(Integer.toHexString(mStartingThemeResId));
sb.append("SplashScreenThemeResName=");
sb.append(mStartingThemeResName);
}
addIndentOrComma(sb, indent);
@@ -2482,7 +2484,8 @@ public final class ShortcutInfo implements Parcelable {
Set<String> categories, Intent[] intentsWithExtras, int rank, PersistableBundle extras,
long lastChangedTimestamp,
int flags, int iconResId, String iconResName, String bitmapPath, String iconUri,
int disabledReason, Person[] persons, LocusId locusId, int startingThemeResId) {
int disabledReason, Person[] persons, LocusId locusId,
@Nullable String startingThemeResName) {
mUserId = userId;
mId = id;
mPackageName = packageName;
@@ -2511,6 +2514,6 @@ public final class ShortcutInfo implements Parcelable {
mDisabledReason = disabledReason;
mPersons = persons;
mLocusId = locusId;
mStartingThemeResId = startingThemeResId;
mStartingThemeResName = startingThemeResName;
}
}

View File

@@ -74,7 +74,7 @@ public abstract class ShortcutServiceInternal {
/**
* Get the theme res ID of the starting window, it can be 0 if not specified.
*/
public abstract int getShortcutStartingThemeResId(int launcherUserId,
public abstract @Nullable String getShortcutStartingThemeResName(int launcherUserId,
@NonNull String callingPackage, @NonNull String packageName, @NonNull String shortcutId,
int userId);

View File

@@ -1000,16 +1000,15 @@ public class LauncherAppsService extends SystemService {
intents[0].setSourceBounds(sourceBounds);
// Replace theme for splash screen
final int splashScreenThemeResId =
mShortcutServiceInternal.getShortcutStartingThemeResId(getCallingUserId(),
final String splashScreenThemeResName =
mShortcutServiceInternal.getShortcutStartingThemeResName(getCallingUserId(),
callingPackage, packageName, shortcutId, targetUserId);
if (splashScreenThemeResId != 0) {
if (splashScreenThemeResName != null && !splashScreenThemeResName.isEmpty()) {
if (startActivityOptions == null) {
startActivityOptions = new Bundle();
}
startActivityOptions.putInt(KEY_SPLASH_SCREEN_THEME, splashScreenThemeResId);
startActivityOptions.putString(KEY_SPLASH_SCREEN_THEME, splashScreenThemeResName);
}
return startShortcutIntentsAsPublisher(
intents, packageName, featureId, startActivityOptions, targetUserId);
}

View File

@@ -139,7 +139,7 @@ class ShortcutPackage extends ShortcutPackageItem {
private static final String ATTR_BITMAP_PATH = "bitmap-path";
private static final String ATTR_ICON_URI = "icon-uri";
private static final String ATTR_LOCUS_ID = "locus-id";
private static final String ATTR_SPLASH_SCREEN_THEME_ID = "splash-screen-theme-id";
private static final String ATTR_SPLASH_SCREEN_THEME_NAME = "splash-screen-theme-name";
private static final String ATTR_PERSON_NAME = "name";
private static final String ATTR_PERSON_URI = "uri";
@@ -1799,7 +1799,7 @@ class ShortcutPackage extends ShortcutPackageItem {
ShortcutService.writeAttr(out, ATTR_TITLE, si.getTitle());
ShortcutService.writeAttr(out, ATTR_TITLE_RES_ID, si.getTitleResId());
ShortcutService.writeAttr(out, ATTR_TITLE_RES_NAME, si.getTitleResName());
ShortcutService.writeAttr(out, ATTR_SPLASH_SCREEN_THEME_ID, si.getStartingThemeResId());
ShortcutService.writeAttr(out, ATTR_SPLASH_SCREEN_THEME_NAME, si.getStartingThemeResName());
ShortcutService.writeAttr(out, ATTR_TEXT, si.getText());
ShortcutService.writeAttr(out, ATTR_TEXT_RES_ID, si.getTextResId());
ShortcutService.writeAttr(out, ATTR_TEXT_RES_NAME, si.getTextResName());
@@ -2010,7 +2010,7 @@ class ShortcutPackage extends ShortcutPackageItem {
String bitmapPath;
String iconUri;
final String locusIdString;
int splashScreenThemeResId;
String splashScreenThemeResName;
int backupVersionCode;
ArraySet<String> categories = null;
ArrayList<Person> persons = new ArrayList<>();
@@ -2021,8 +2021,8 @@ class ShortcutPackage extends ShortcutPackageItem {
title = ShortcutService.parseStringAttribute(parser, ATTR_TITLE);
titleResId = ShortcutService.parseIntAttribute(parser, ATTR_TITLE_RES_ID);
titleResName = ShortcutService.parseStringAttribute(parser, ATTR_TITLE_RES_NAME);
splashScreenThemeResId = ShortcutService.parseIntAttribute(parser,
ATTR_SPLASH_SCREEN_THEME_ID);
splashScreenThemeResName = ShortcutService.parseStringAttribute(parser,
ATTR_SPLASH_SCREEN_THEME_NAME);
text = ShortcutService.parseStringAttribute(parser, ATTR_TEXT);
textResId = ShortcutService.parseIntAttribute(parser, ATTR_TEXT_RES_ID);
textResName = ShortcutService.parseStringAttribute(parser, ATTR_TEXT_RES_NAME);
@@ -2117,7 +2117,7 @@ class ShortcutPackage extends ShortcutPackageItem {
rank, extras, lastChangedTimestamp, flags,
iconResId, iconResName, bitmapPath, iconUri,
disabledReason, persons.toArray(new Person[persons.size()]), locusId,
splashScreenThemeResId);
splashScreenThemeResName);
}
private static Intent parseIntent(TypedXmlPullParser parser)

View File

@@ -383,8 +383,11 @@ public class ShortcutParser {
final int textResId = sa.getResourceId(R.styleable.Shortcut_shortcutLongLabel, 0);
final int disabledMessageResId = sa.getResourceId(
R.styleable.Shortcut_shortcutDisabledMessage, 0);
final int splashScreenTheme = sa.getResourceId(
final int splashScreenThemeResId = sa.getResourceId(
R.styleable.Shortcut_splashScreenTheme, 0);
final String splashScreenThemeResName = splashScreenThemeResId != 0
? service.mContext.getResources().getResourceName(splashScreenThemeResId)
: null;
if (TextUtils.isEmpty(id)) {
Log.w(TAG, "android:shortcutId must be provided. activity=" + activity);
@@ -407,7 +410,7 @@ public class ShortcutParser {
rank,
iconResId,
enabled,
splashScreenTheme);
splashScreenThemeResName);
} finally {
sa.recycle();
}
@@ -416,7 +419,7 @@ public class ShortcutParser {
private static ShortcutInfo createShortcutFromManifest(ShortcutService service,
@UserIdInt int userId, String id, String packageName, ComponentName activityComponent,
int titleResId, int textResId, int disabledMessageResId,
int rank, int iconResId, boolean enabled, int splashScreenTheme) {
int rank, int iconResId, boolean enabled, @Nullable String splashScreenThemeResName) {
final int flags =
(enabled ? ShortcutInfo.FLAG_MANIFEST : ShortcutInfo.FLAG_DISABLED)
@@ -456,7 +459,7 @@ public class ShortcutParser {
disabledReason,
null /* persons */,
null /* locusId */,
splashScreenTheme);
splashScreenThemeResName);
}
private static String parseCategory(ShortcutService service, AttributeSet attrs) {

View File

@@ -3536,7 +3536,8 @@ public class ShortcutService extends IShortcutService.Stub {
}
@Override
public int getShortcutStartingThemeResId(int launcherUserId,
@Nullable
public String getShortcutStartingThemeResName(int launcherUserId,
@NonNull String callingPackage, @NonNull String packageName,
@NonNull String shortcutId, int userId) {
Objects.requireNonNull(callingPackage, "callingPackage");
@@ -3553,11 +3554,11 @@ public class ShortcutService extends IShortcutService.Stub {
final ShortcutPackage p = getUserShortcutsLocked(userId)
.getPackageShortcutsIfExists(packageName);
if (p == null) {
return 0;
return null;
}
final ShortcutInfo shortcutInfo = p.findShortcutById(shortcutId);
return shortcutInfo != null ? shortcutInfo.getStartingThemeResId() : 0;
return shortcutInfo != null ? shortcutInfo.getStartingThemeResName() : null;
}
}

View File

@@ -6689,24 +6689,26 @@ class Task extends WindowContainer<WindowContainer> {
}
}
// TODO(185200798): Persist theme name instead of theme if
int splashScreenThemeResId = options != null
? options.getSplashScreenThemeResId() : 0;
// User can override the splashscreen theme. The theme name is used to persist
// the setting, so if no theme is set in the ActivityOptions, we check if has
// been persisted here.
if (splashScreenThemeResId == 0) {
// Find the splash screen theme. User can override the persisted theme by
// ActivityOptions.
String splashScreenThemeResName = options != null
? options.getSplashScreenThemeResName() : null;
if (splashScreenThemeResName == null || splashScreenThemeResName.isEmpty()) {
try {
String themeName = mAtmService.getPackageManager()
splashScreenThemeResName = mAtmService.getPackageManager()
.getSplashScreenTheme(r.packageName, r.mUserId);
if (themeName != null) {
Context packageContext = mAtmService.mContext
.createPackageContext(r.packageName, 0);
splashScreenThemeResId = packageContext.getResources()
.getIdentifier(themeName, null, null);
}
} catch (RemoteException | PackageManager.NameNotFoundException
} catch (RemoteException ignore) {
// Just use the default theme
}
}
int splashScreenThemeResId = 0;
if (splashScreenThemeResName != null && !splashScreenThemeResName.isEmpty()) {
try {
final Context packageContext = mAtmService.mContext
.createPackageContext(r.packageName, 0);
splashScreenThemeResId = packageContext.getResources()
.getIdentifier(splashScreenThemeResName, null, null);
} catch (PackageManager.NameNotFoundException
| Resources.NotFoundException ignore) {
// Just use the default theme
}

View File

@@ -253,6 +253,7 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest {
.setPerson(makePerson("person", "personKey", "personUri"))
.setLongLived(true)
.setExtras(pb)
.setStartingTheme(android.R.style.Theme_Black_NoTitleBar_Fullscreen)
.build();
si.addFlags(ShortcutInfo.FLAG_PINNED);
si.setBitmapPath("abc");
@@ -288,6 +289,8 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest {
assertEquals(null, si.getTextResName());
assertEquals(0, si.getDisabledMessageResourceId());
assertEquals(null, si.getDisabledMessageResName());
assertEquals("android:style/Theme.Black.NoTitleBar.Fullscreen",
si.getStartingThemeResName());
}
public void testShortcutInfoParcel_resId() {
@@ -308,6 +311,7 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest {
.setCategories(set(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION, "xyz"))
.setRank(123)
.setExtras(pb)
.setStartingTheme(android.R.style.Theme_Black_NoTitleBar_Fullscreen)
.build();
si.addFlags(ShortcutInfo.FLAG_PINNED);
si.setBitmapPath("abc");
@@ -339,6 +343,8 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest {
assertEquals(456, si.getIconResourceId());
assertEquals("string/r456", si.getIconResName());
assertEquals("test_uri", si.getIconUri());
assertEquals("android:style/Theme.Black.NoTitleBar.Fullscreen",
si.getStartingThemeResName());
}
public void testShortcutInfoClone() {
@@ -2210,6 +2216,10 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest {
android.R.drawable.alert_dark_frame, true, getTestContext().getPackageName()));
assertEquals("" + android.R.string.cancel, ShortcutInfo.lookUpResourceName(res,
android.R.string.cancel, false, getTestContext().getPackageName()));
assertEquals("" + android.R.style.Theme_Black_NoTitleBar_Fullscreen,
ShortcutInfo.lookUpResourceName(
res, android.R.style.Theme_Black_NoTitleBar_Fullscreen, true,
getTestContext().getPackageName()));
}
public void testLookUpResourceName_appResources() {
@@ -2236,6 +2246,10 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest {
assertEquals(android.R.drawable.alert_dark_frame, ShortcutInfo.lookUpResourceId(res,
"" + android.R.drawable.alert_dark_frame, null,
getTestContext().getPackageName()));
assertEquals(android.R.style.Theme_Black_NoTitleBar_Fullscreen,
ShortcutInfo.lookUpResourceId(
res, "" + android.R.style.Theme_Black_NoTitleBar_Fullscreen,
null, getTestContext().getPackageName()));
}
// Test for a ShortcutInfo method.

View File

@@ -394,7 +394,7 @@ public class NotificationListenerServiceTest extends UiServiceTestCase {
"disabledMessage", 0, "disabledMessageResName",
null, null, 0, null, 0, 0,
0, "iconResName", "bitmapPath", null, 0,
null, null, 0);
null, null, null);
return si;
}