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

Commit a02c6340 authored by Omar Eissa's avatar Omar Eissa Committed by Alex Buynytskyy
Browse files

Add new method notifyComponentUsed.

Define a new method notifyComponentUsed that is being called when app
component (except broadcast recevier) has been used. This is the first
step so that it could be easier to change the reaction of
PackageManagerService on such event when needed. This CL should work as no-op.

Test: Manual
Bug: 269127435
Change-Id: Icc62c0aa132942bb758db66f214fdf047844398c
parent 6db03d57
Loading
Loading
Loading
Loading
+7 −0
Original line number Original line Diff line number Diff line
@@ -1369,6 +1369,13 @@ public abstract class PackageManagerInternal {
    public abstract void setPackageStoppedState(@NonNull String packageName, boolean stopped,
    public abstract void setPackageStoppedState(@NonNull String packageName, boolean stopped,
            @UserIdInt int userId);
            @UserIdInt int userId);


    /**
     * Tells PackageManager when a component (except BroadcastReceivers) of the package is used
     * and the package should get out of stopped state and be enabled.
     */
    public abstract void notifyComponentUsed(@NonNull String packageName,
            @UserIdInt int userId, @NonNull String recentCallingPackage);

    /** @deprecated For legacy shell command only. */
    /** @deprecated For legacy shell command only. */
    @Deprecated
    @Deprecated
    public abstract void legacyDumpProfiles(@NonNull String packageName,
    public abstract void legacyDumpProfiles(@NonNull String packageName,
+2 −3
Original line number Original line Diff line number Diff line
@@ -5116,10 +5116,9 @@ public final class ActiveServices {
                    r.packageName, r.userId, UsageEvents.Event.APP_COMPONENT_USED);
                    r.packageName, r.userId, UsageEvents.Event.APP_COMPONENT_USED);
        }
        }


        // Service is now being launched, its package can't be stopped.
        try {
        try {
            mAm.mPackageManagerInt.setPackageStoppedState(
            mAm.mPackageManagerInt.notifyComponentUsed(
                    r.packageName, false, r.userId);
                    r.packageName, r.userId, r.mRecentCallingPackage);
        } catch (IllegalArgumentException e) {
        } catch (IllegalArgumentException e) {
            Slog.w(TAG, "Failed trying to unstop package "
            Slog.w(TAG, "Failed trying to unstop package "
                    + r.packageName + ": " + e);
                    + r.packageName + ": " + e);
+2 −3
Original line number Original line Diff line number Diff line
@@ -505,12 +505,11 @@ public class ContentProviderHelper {
                                    cpr.appInfo.packageName, userId, Event.APP_COMPONENT_USED);
                                    cpr.appInfo.packageName, userId, Event.APP_COMPONENT_USED);
                        }
                        }


                        // Content provider is now in use, its package can't be stopped.
                        try {
                        try {
                            checkTime(startTime,
                            checkTime(startTime,
                                    "getContentProviderImpl: before set stopped state");
                                    "getContentProviderImpl: before set stopped state");
                            mService.mPackageManagerInt.setPackageStoppedState(
                            mService.mPackageManagerInt.notifyComponentUsed(
                                    cpr.appInfo.packageName, false, userId);
                                    cpr.appInfo.packageName, userId, callingPackage);
                            checkTime(startTime, "getContentProviderImpl: after set stopped state");
                            checkTime(startTime, "getContentProviderImpl: after set stopped state");
                        } catch (IllegalArgumentException e) {
                        } catch (IllegalArgumentException e) {
                            Slog.w(TAG, "Failed trying to unstop package "
                            Slog.w(TAG, "Failed trying to unstop package "
+7 −0
Original line number Original line Diff line number Diff line
@@ -745,6 +745,13 @@ abstract class PackageManagerInternalBase extends PackageManagerInternal {
        mService.setPackageStoppedState(snapshot(), packageName, stopped, userId);
        mService.setPackageStoppedState(snapshot(), packageName, stopped, userId);
    }
    }


    @Override
    public void notifyComponentUsed(@NonNull String packageName,
            @UserIdInt int userId, @NonNull String recentCallingPackage) {
        mService.notifyComponentUsed(snapshot(), packageName, userId,
                recentCallingPackage);
    }

    @NonNull
    @NonNull
    @Override
    @Override
    @Deprecated
    @Deprecated
+7 −0
Original line number Original line Diff line number Diff line
@@ -4582,6 +4582,13 @@ public class PackageManagerService implements PackageSender, TestUtilityService
        }
        }
    }
    }


    void notifyComponentUsed(@NonNull Computer snapshot, @NonNull String packageName,
            @UserIdInt int userId, @NonNull String recentCallingPackage) {
        PackageManagerService.this
                .setPackageStoppedState(snapshot, packageName, false /* stopped */,
                        userId);
    }

    public class IPackageManagerImpl extends IPackageManagerBase {
    public class IPackageManagerImpl extends IPackageManagerBase {


        public IPackageManagerImpl() {
        public IPackageManagerImpl() {
Loading