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

Commit b69f2bc1 authored by Steven Thomas's avatar Steven Thomas Committed by Android (Google) Code Review
Browse files

Merge changes from topic "revert-10403399-pkg-override-label-icon-DCRMJNYAKW" into rvc-dev

* changes:
  Revert "Add test constructor to PackageManagerService"
  Revert "Allow overriding the label and icon of a MainComponent"
parents f3364db2 835348a5
Loading
Loading
Loading
Loading
+0 −29
Original line number Diff line number Diff line
@@ -305,35 +305,6 @@ 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}.
     */
+0 −71
Original line number Diff line number Diff line
@@ -27,24 +27,18 @@ 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;
@@ -90,9 +84,6 @@ 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;
@@ -132,9 +123,6 @@ public class PackageUserState {
            sharedLibraryOverlayPaths = new ArrayMap<>(o.sharedLibraryOverlayPaths);
        }
        harmfulAppWarning = o.harmfulAppWarning;
        if (o.componentLabelIconOverrideMap != null) {
            this.componentLabelIconOverrideMap = new ArrayMap<>(o.componentLabelIconOverrideMap);
        }
    }

    public String[] getOverlayPaths() {
@@ -158,65 +146,6 @@ public class PackageUserState {
        cachedOverlayPaths = null;
    }

    /**
     * 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.
     */
+0 −3
Original line number Diff line number Diff line
@@ -1910,9 +1910,6 @@
    <!-- The name of the package that will hold the system gallery role. -->
    <string name="config_systemGallery" translatable="false">com.android.gallery</string>

    <!-- The name of the package that will be allowed to change its components' label/icon. -->
    <string name="config_overrideComponentUiPackage" translatable="false"></string>

    <!-- Enable/disable default bluetooth profiles:
        HSP_AG, ObexObjectPush, Audio, NAP -->
    <bool name="config_bluetooth_default_profiles">true</bool>
+0 −2
Original line number Diff line number Diff line
@@ -3961,6 +3961,4 @@

  <!-- Set to true to make assistant show in front of the dream/screensaver. -->
  <java-symbol type="bool" name="config_assistantOnTopOfDream"/>

  <java-symbol type="string" name="config_overrideComponentUiPackage" />
</resources>
+4 −29
Original line number Diff line number Diff line
@@ -54,7 +54,6 @@ import android.util.Pair;
import android.util.Slog;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.ArrayUtils;
import com.android.server.IntentResolver;
import com.android.server.pm.parsing.PackageInfoUtils;
@@ -208,57 +207,33 @@ public class ComponentResolver {
    }

    /** Returns the given activity */
    @Nullable
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
    public ParsedActivity getActivity(@NonNull ComponentName component) {
    ParsedActivity getActivity(ComponentName component) {
        synchronized (mLock) {
            return mActivities.mActivities.get(component);
        }
    }

    /** Returns the given provider */
    @Nullable
    ParsedProvider getProvider(@NonNull ComponentName component) {
    ParsedProvider getProvider(ComponentName component) {
        synchronized (mLock) {
            return mProviders.mProviders.get(component);
        }
    }

    /** Returns the given receiver */
    @Nullable
    ParsedActivity getReceiver(@NonNull ComponentName component) {
    ParsedActivity getReceiver(ComponentName component) {
        synchronized (mLock) {
            return mReceivers.mActivities.get(component);
        }
    }

    /** Returns the given service */
    @Nullable
    ParsedService getService(@NonNull ComponentName component) {
    ParsedService getService(ComponentName component) {
        synchronized (mLock) {
            return mServices.mServices.get(component);
        }
    }

    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
    public boolean componentExists(@NonNull ComponentName componentName) {
        synchronized (mLock) {
            ParsedMainComponent component = mActivities.mActivities.get(componentName);
            if (component != null) {
                return true;
            }
            component = mReceivers.mActivities.get(componentName);
            if (component != null) {
                return true;
            }
            component = mServices.mServices.get(componentName);
            if (component != null) {
                return true;
            }
            return mProviders.mProviders.get(componentName) != null;
        }
    }

    @Nullable
    List<ResolveInfo> queryActivities(Intent intent, String resolvedType, int flags,
            @PrivateResolveFlags int privateResolveFlags, int userId) {
Loading