summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorWinson Chiu <chiuwinson@google.com>2020-04-02 07:49:40 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2020-04-02 07:49:40 +0000
commitbd24ca3daf1dafe8163aafd595068033636ce309 (patch)
tree5c99913f1dbf9b3c765ba26521d8d17f8ebf8dc6 /core/java/android
parent5f971a2584319859603bcee3a93719446c610427 (diff)
parent5cda4548108894d175ec6eaa578d193501bd6ae3 (diff)
Merge changes from topic "revert-10921255-revert-10403399-pkg-override-label-icon-DCRMJNYAKW-YCXMFEDIAG" into rvc-dev
* changes: Add mPackageParserCallback assignment in TestParams constructor Revert "Revert "Allow overriding the label and icon of a MainCom..." Revert^2 "Add test constructor to PackageManagerService"
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/content/pm/IPackageManager.aidl29
-rw-r--r--core/java/android/content/pm/PackageUserState.java71
2 files changed, 100 insertions, 0 deletions
diff --git a/core/java/android/content/pm/IPackageManager.aidl b/core/java/android/content/pm/IPackageManager.aidl
index 5bad055810cc..8bebafff37f0 100644
--- a/core/java/android/content/pm/IPackageManager.aidl
+++ b/core/java/android/content/pm/IPackageManager.aidl
@@ -306,6 +306,35 @@ interface IPackageManager {
void setHomeActivity(in ComponentName className, int userId);
/**
+ * Overrides the label and icon of the component specified by the component name. The component
+ * must belong to the calling app.
+ *
+ * These changes will be reset on the next boot and whenever the package is updated.
+ *
+ * Only the app defined as com.android.internal.R.config_overrideComponentUiPackage is allowed
+ * to call this.
+ *
+ * @param componentName The component name to override the label/icon of.
+ * @param nonLocalizedLabel The label to be displayed.
+ * @param icon The icon to be displayed.
+ * @param userId The user id.
+ */
+ void overrideLabelAndIcon(in ComponentName componentName, String nonLocalizedLabel,
+ int icon, int userId);
+
+ /**
+ * Restores the label and icon of the activity specified by the component name if either has
+ * been overridden. The component must belong to the calling app.
+ *
+ * Only the app defined as com.android.internal.R.config_overrideComponentUiPackage is allowed
+ * to call this.
+ *
+ * @param componentName The component name.
+ * @param userId The user id.
+ */
+ void restoreLabelAndIcon(in ComponentName componentName, int userId);
+
+ /**
* As per {@link android.content.pm.PackageManager#setComponentEnabledSetting}.
*/
@UnsupportedAppUsage
diff --git a/core/java/android/content/pm/PackageUserState.java b/core/java/android/content/pm/PackageUserState.java
index 61b1553e28a8..327d1b8beeb1 100644
--- a/core/java/android/content/pm/PackageUserState.java
+++ b/core/java/android/content/pm/PackageUserState.java
@@ -27,18 +27,24 @@ import static android.content.pm.PackageManager.MATCH_DISABLED_COMPONENTS;
import static android.content.pm.PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS;
import static android.content.pm.PackageManager.MATCH_SYSTEM_ONLY;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.compat.annotation.UnsupportedAppUsage;
+import android.content.ComponentName;
import android.content.pm.parsing.component.ParsedMainComponent;
import android.os.BaseBundle;
import android.os.Debug;
import android.os.PersistableBundle;
+import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.DebugUtils;
+import android.util.Pair;
import android.util.Slog;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.ArrayUtils;
+import com.android.internal.util.CollectionUtils;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -84,6 +90,9 @@ public class PackageUserState {
private ArrayMap<String, String[]> sharedLibraryOverlayPaths; // Lib name to overlay paths
private String[] cachedOverlayPaths;
+ @Nullable
+ private ArrayMap<ComponentName, Pair<String, Integer>> componentLabelIconOverrideMap;
+
@UnsupportedAppUsage
public PackageUserState() {
installed = true;
@@ -123,6 +132,9 @@ public class PackageUserState {
sharedLibraryOverlayPaths = new ArrayMap<>(o.sharedLibraryOverlayPaths);
}
harmfulAppWarning = o.harmfulAppWarning;
+ if (o.componentLabelIconOverrideMap != null) {
+ this.componentLabelIconOverrideMap = new ArrayMap<>(o.componentLabelIconOverrideMap);
+ }
}
public String[] getOverlayPaths() {
@@ -147,6 +159,65 @@ public class PackageUserState {
}
/**
+ * Overrides the non-localized label and icon of a component.
+ *
+ * @return true if the label or icon was changed.
+ */
+ @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
+ public boolean overrideLabelAndIcon(@NonNull ComponentName component,
+ @Nullable String nonLocalizedLabel, @Nullable Integer icon) {
+ String existingLabel = null;
+ Integer existingIcon = null;
+
+ if (componentLabelIconOverrideMap != null) {
+ Pair<String, Integer> pair = componentLabelIconOverrideMap.get(component);
+ if (pair != null) {
+ existingLabel = pair.first;
+ existingIcon = pair.second;
+ }
+ }
+
+ boolean changed = !TextUtils.equals(existingLabel, nonLocalizedLabel)
+ || !Objects.equals(existingIcon, icon);
+
+ if (changed) {
+ if (nonLocalizedLabel == null && icon == null) {
+ componentLabelIconOverrideMap.remove(component);
+ if (componentLabelIconOverrideMap.isEmpty()) {
+ componentLabelIconOverrideMap = null;
+ }
+ } else {
+ if (componentLabelIconOverrideMap == null) {
+ componentLabelIconOverrideMap = new ArrayMap<>(1);
+ }
+
+ componentLabelIconOverrideMap.put(component, Pair.create(nonLocalizedLabel, icon));
+ }
+ }
+
+ return changed;
+ }
+
+ /**
+ * Clears all values previously set by {@link #overrideLabelAndIcon(ComponentName,
+ * String, Integer)}.
+ *
+ * This is done when the package is updated as the components and resource IDs may have changed.
+ */
+ public void resetOverrideComponentLabelIcon() {
+ componentLabelIconOverrideMap = null;
+ }
+
+ @Nullable
+ public Pair<String, Integer> getOverrideLabelIconForComponent(ComponentName componentName) {
+ if (ArrayUtils.isEmpty(componentLabelIconOverrideMap)) {
+ return null;
+ }
+
+ return componentLabelIconOverrideMap.get(componentName);
+ }
+
+ /**
* Test if this package is installed.
*/
public boolean isAvailable(int flags) {