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

Commit 8ac0d0d5 authored by Felipe Leme's avatar Felipe Leme
Browse files

Minor fixes for devices without WallpaperService.

- Fixed constructors so DisabledWallpaperManager doesn't throw exception
- Fixed SystemServiceRegistry.get(WallpaperManager.class) for instant apps

Bug: 138939803
Test: atest --instant CtsPermissionTestCases:android.permission.cts.ServicesInstantAppsCannotAccessTests#cannotGetWallpaperManager

Change-Id: I7cd6c65e9a693f3f1c4d5232420cc3f881d398c1
parent 8bc4b047
Loading
Loading
Loading
Loading
+6 −7
Original line number Diff line number Diff line
@@ -41,8 +41,7 @@ final class DisabledWallpaperManager extends WallpaperManager {
    // Don't need to worry about synchronization
    private static DisabledWallpaperManager sInstance;

    // TODO(b/138939803): STOPSHIP changed to false and/or remove it
    private static final boolean DEBUG = true;
    private static final boolean DEBUG = false;

    @NonNull
    static DisabledWallpaperManager getInstance() {
@@ -53,7 +52,6 @@ final class DisabledWallpaperManager extends WallpaperManager {
    }

    private DisabledWallpaperManager() {
        super(null, null, null);
    }

    @Override
@@ -66,10 +64,6 @@ final class DisabledWallpaperManager extends WallpaperManager {
        return false;
    }

    // TODO(b/138939803): STOPSHIP methods below should not be necessary,
    // callers should check if isWallpaperSupported(), consider removing them to keep this class
    // simpler

    private static <T> T unsupported() {
        if (DEBUG) Log.w(TAG, "unsupported method called; returning null", new Exception());
        return null;
@@ -343,4 +337,9 @@ final class DisabledWallpaperManager extends WallpaperManager {
    public boolean isWallpaperBackupEligible(int which) {
        return unsupportedBoolean();
    }

    @Override
    public boolean wallpaperSupportsWcg(int which) {
        return unsupportedBoolean();
    }
}
+9 −8
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ import android.content.integrity.AppIntegrityManager;
import android.content.integrity.IAppIntegrityManager;
import android.content.om.IOverlayManager;
import android.content.om.OverlayManager;
import android.content.pm.ApplicationInfo;
import android.content.pm.CrossProfileApps;
import android.content.pm.DataLoaderManager;
import android.content.pm.ICrossProfileApps;
@@ -677,20 +678,20 @@ public final class SystemServiceRegistry {
                    throws ServiceNotFoundException {
                final IBinder b = ServiceManager.getService(Context.WALLPAPER_SERVICE);
                if (b == null) {
                    // There are 2 reason service can be null:
                    // 1.Device doesn't support it - that's fine
                    // 2.App is running on instant mode - should fail
                    ApplicationInfo appInfo = ctx.getApplicationInfo();
                    if (appInfo.targetSdkVersion >= Build.VERSION_CODES.P
                            && appInfo.isInstantApp()) {
                        // Instant app
                        throw new ServiceNotFoundException(Context.WALLPAPER_SERVICE);
                    }
                    final boolean enabled = Resources.getSystem()
                            .getBoolean(com.android.internal.R.bool.config_enableWallpaperService);
                    if (!enabled) {
                        // Life moves on...
                        // Device doesn't support wallpaper, return a limited manager
                        return DisabledWallpaperManager.getInstance();
                    }
                    if (ctx.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.P) {
                        // Instant app
                        throw new ServiceNotFoundException(Context.WALLPAPER_SERVICE);
                    }
                    // Bad state - WallpaperManager methods will throw exception
                    Log.e(TAG, "No wallpaper service");
                }
                IWallpaperManager service = IWallpaperManager.Stub.asInterface(b);
                return new WallpaperManager(service, ctx.getOuterContext(),
+7 −0
Original line number Diff line number Diff line
@@ -543,6 +543,13 @@ public class WallpaperManager {
        mCmProxy = new ColorManagementProxy(context);
    }

    // no-op constructor called just by DisabledWallpaperManager
    /*package*/ WallpaperManager() {
        mContext = null;
        mCmProxy = null;
        mWcgEnabled = false;
    }

    /**
     * Retrieve a WallpaperManager associated with the given Context.
     */