Loading services/core/java/com/android/server/appwindowlayout/AppWindowLayoutSettingsRestoreStorage.java +5 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.content.Context; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.os.Environment; import android.util.Slog; import com.android.internal.annotations.VisibleForTesting; Loading @@ -41,6 +42,8 @@ import java.time.InstantSource; */ @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) public class AppWindowLayoutSettingsRestoreStorage { private static final String TAG = "AppWinLayoutSetStorage"; // TODO(b/414361710): Consider joining this class implementation with the Settings app // UserAspectRatioRestoreStorage, or removing the Settings class implementation if it is not // needed after restoreUserAspectRatioSettingsUsingService flag is launched. Loading Loading @@ -122,6 +125,8 @@ public class AppWindowLayoutSettingsRestoreStorage { KEY_STAGED_DATA_TIME, 0)); if (Duration.between(restoreTime, mInstantSource.instant()).compareTo(EXPIRY_DURATION) >= 0) { Slog.d(TAG, "Restore time expired. Deleting packages: " + mUserAspectRatioSharedPreferences.getAll()); // Remove the restore time and all data to restore. mUserAspectRatioSharedPreferences.edit().clear().commit(); mRestoreTimeSharedPreferences.edit().clear().commit(); Loading services/core/java/com/android/server/appwindowlayout/AppWindowLayoutSettingsService.java +11 −11 Original line number Diff line number Diff line Loading @@ -57,8 +57,6 @@ import java.util.List; public class AppWindowLayoutSettingsService extends SystemService { private static final String TAG = "AppWinLayoutSetService"; private static final boolean DEBUG = false; @NonNull private final Context mContext; @NonNull Loading Loading @@ -86,9 +84,8 @@ public class AppWindowLayoutSettingsService extends SystemService { mIPackageManager = AppGlobals.getPackageManager(); mPackageMonitor = new AppWindowLayoutSettingsPackageMonitor(); mPackageMonitor.setCallback(this::onPackageAdded); final HandlerThread handlerThread = new HandlerThread("AppWinLayoutSetService", mBackgroundThread = new HandlerThread("AppWinLayoutSetService", THREAD_PRIORITY_BACKGROUND); mBackgroundThread = handlerThread; mBackgroundThread.start(); } Loading @@ -98,9 +95,8 @@ public class AppWindowLayoutSettingsService extends SystemService { mIPackageManager = AppGlobals.getPackageManager(); mPackageMonitor = new AppWindowLayoutSettingsPackageMonitor(); mPackageMonitor.setCallback(this::onPackageAdded); final HandlerThread handlerThread = new HandlerThread("AppWinLayoutSetService", mBackgroundThread = new HandlerThread("AppWinLayoutSetService", THREAD_PRIORITY_BACKGROUND); mBackgroundThread = handlerThread; mBackgroundThread.start(); } Loading Loading @@ -140,6 +136,8 @@ public class AppWindowLayoutSettingsService extends SystemService { public void awaitPackageInstallForAspectRatio(@NonNull String packageName, @UserIdInt int userId, @PackageManager.UserMinAspectRatio int aspectRatio) { Slog.d(TAG, "Await package installed " + packageName + " to restore aspect ratio: " + aspectRatio); synchronized (mLock) { createAndGetStorage(userId).storePackageAndUserAspectRatio(packageName, aspectRatio); Loading @@ -148,9 +146,12 @@ public class AppWindowLayoutSettingsService extends SystemService { } private void onPackageAdded(@NonNull String packageName, @UserIdInt int userId) { Slog.d(TAG, "Notified package installed: " + packageName); synchronized (mLock) { final AppWindowLayoutSettingsRestoreStorage storage = createAndGetStorage(userId); final int aspectRatio = storage.getAndRemoveUserAspectRatioForPackage(packageName); Slog.d(TAG, "Found aspect ratio: " + aspectRatio + " for package: " + packageName); if (aspectRatio != USER_MIN_ASPECT_RATIO_UNSET) { checkExistingAspectRatioAndApplyRestore(packageName, userId, aspectRatio); } Loading Loading @@ -178,6 +179,7 @@ public class AppWindowLayoutSettingsService extends SystemService { mIsPackageMonitorRegistered = true; mPackageMonitor.register(this.getContext(), mBackgroundThread.getLooper(), UserHandle.ALL, true); Slog.d(TAG, "Registered package monitor for restoring aspect ratios."); } } Loading @@ -186,6 +188,7 @@ public class AppWindowLayoutSettingsService extends SystemService { if (mIsPackageMonitorRegistered) { mIsPackageMonitorRegistered = false; mPackageMonitor.unregister(); Slog.d(TAG, "Unregistered package monitor."); } } Loading @@ -198,16 +201,13 @@ public class AppWindowLayoutSettingsService extends SystemService { // Don't apply the restore if the aspect ratio have already been set for the app. // Packages which are not yet installed will return `USER_MIN_ASPECT_RATIO_UNSET`. if (existingUserAspectRatio != USER_MIN_ASPECT_RATIO_UNSET) { Slog.d(TAG, "Not restoring user aspect ratio=" + aspectRatio + " for package=" Slog.d(TAG, "Not restoring user aspect ratio: " + aspectRatio + " for package: " + pkgName + " as it is already set to " + existingUserAspectRatio + "."); return; } mIPackageManager.setUserMinAspectRatio(pkgName, userId, aspectRatio); if (DEBUG) { Slog.d(TAG, "Restored user aspect ratio=" + aspectRatio + " for package=" + pkgName); } Slog.d(TAG, "Restored user aspect ratio: " + aspectRatio + " for package: " + pkgName); } catch (Exception e) { Slog.e(TAG, "Could not restore user aspect ratio for package " + pkgName, e); } Loading services/core/java/com/android/server/pm/PackageManagerService.java +3 −0 Original line number Diff line number Diff line Loading @@ -6588,6 +6588,9 @@ public class PackageManagerService implements PackageSender, TestUtilityService .getPackageStateForInstalledAndFiltered(packageName, callingUid, userId); if (packageState == null) { if (com.android.window.flags.Flags.restoreUserAspectRatioSettingsUsingService()) { Slog.d(TAG, "Package: " + packageName + " not yet installed. " + "Scheduling aspect ratio update upon install, for aspect ratio: " + aspectRatio); // Pass along the request to `AppWindowLayoutSettingsService`, which will retry // to set the user aspect ratio after the package has been installed. final AppWindowLayoutSettingsService appWindowLayoutSettingsService = Loading Loading
services/core/java/com/android/server/appwindowlayout/AppWindowLayoutSettingsRestoreStorage.java +5 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.content.Context; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.os.Environment; import android.util.Slog; import com.android.internal.annotations.VisibleForTesting; Loading @@ -41,6 +42,8 @@ import java.time.InstantSource; */ @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) public class AppWindowLayoutSettingsRestoreStorage { private static final String TAG = "AppWinLayoutSetStorage"; // TODO(b/414361710): Consider joining this class implementation with the Settings app // UserAspectRatioRestoreStorage, or removing the Settings class implementation if it is not // needed after restoreUserAspectRatioSettingsUsingService flag is launched. Loading Loading @@ -122,6 +125,8 @@ public class AppWindowLayoutSettingsRestoreStorage { KEY_STAGED_DATA_TIME, 0)); if (Duration.between(restoreTime, mInstantSource.instant()).compareTo(EXPIRY_DURATION) >= 0) { Slog.d(TAG, "Restore time expired. Deleting packages: " + mUserAspectRatioSharedPreferences.getAll()); // Remove the restore time and all data to restore. mUserAspectRatioSharedPreferences.edit().clear().commit(); mRestoreTimeSharedPreferences.edit().clear().commit(); Loading
services/core/java/com/android/server/appwindowlayout/AppWindowLayoutSettingsService.java +11 −11 Original line number Diff line number Diff line Loading @@ -57,8 +57,6 @@ import java.util.List; public class AppWindowLayoutSettingsService extends SystemService { private static final String TAG = "AppWinLayoutSetService"; private static final boolean DEBUG = false; @NonNull private final Context mContext; @NonNull Loading Loading @@ -86,9 +84,8 @@ public class AppWindowLayoutSettingsService extends SystemService { mIPackageManager = AppGlobals.getPackageManager(); mPackageMonitor = new AppWindowLayoutSettingsPackageMonitor(); mPackageMonitor.setCallback(this::onPackageAdded); final HandlerThread handlerThread = new HandlerThread("AppWinLayoutSetService", mBackgroundThread = new HandlerThread("AppWinLayoutSetService", THREAD_PRIORITY_BACKGROUND); mBackgroundThread = handlerThread; mBackgroundThread.start(); } Loading @@ -98,9 +95,8 @@ public class AppWindowLayoutSettingsService extends SystemService { mIPackageManager = AppGlobals.getPackageManager(); mPackageMonitor = new AppWindowLayoutSettingsPackageMonitor(); mPackageMonitor.setCallback(this::onPackageAdded); final HandlerThread handlerThread = new HandlerThread("AppWinLayoutSetService", mBackgroundThread = new HandlerThread("AppWinLayoutSetService", THREAD_PRIORITY_BACKGROUND); mBackgroundThread = handlerThread; mBackgroundThread.start(); } Loading Loading @@ -140,6 +136,8 @@ public class AppWindowLayoutSettingsService extends SystemService { public void awaitPackageInstallForAspectRatio(@NonNull String packageName, @UserIdInt int userId, @PackageManager.UserMinAspectRatio int aspectRatio) { Slog.d(TAG, "Await package installed " + packageName + " to restore aspect ratio: " + aspectRatio); synchronized (mLock) { createAndGetStorage(userId).storePackageAndUserAspectRatio(packageName, aspectRatio); Loading @@ -148,9 +146,12 @@ public class AppWindowLayoutSettingsService extends SystemService { } private void onPackageAdded(@NonNull String packageName, @UserIdInt int userId) { Slog.d(TAG, "Notified package installed: " + packageName); synchronized (mLock) { final AppWindowLayoutSettingsRestoreStorage storage = createAndGetStorage(userId); final int aspectRatio = storage.getAndRemoveUserAspectRatioForPackage(packageName); Slog.d(TAG, "Found aspect ratio: " + aspectRatio + " for package: " + packageName); if (aspectRatio != USER_MIN_ASPECT_RATIO_UNSET) { checkExistingAspectRatioAndApplyRestore(packageName, userId, aspectRatio); } Loading Loading @@ -178,6 +179,7 @@ public class AppWindowLayoutSettingsService extends SystemService { mIsPackageMonitorRegistered = true; mPackageMonitor.register(this.getContext(), mBackgroundThread.getLooper(), UserHandle.ALL, true); Slog.d(TAG, "Registered package monitor for restoring aspect ratios."); } } Loading @@ -186,6 +188,7 @@ public class AppWindowLayoutSettingsService extends SystemService { if (mIsPackageMonitorRegistered) { mIsPackageMonitorRegistered = false; mPackageMonitor.unregister(); Slog.d(TAG, "Unregistered package monitor."); } } Loading @@ -198,16 +201,13 @@ public class AppWindowLayoutSettingsService extends SystemService { // Don't apply the restore if the aspect ratio have already been set for the app. // Packages which are not yet installed will return `USER_MIN_ASPECT_RATIO_UNSET`. if (existingUserAspectRatio != USER_MIN_ASPECT_RATIO_UNSET) { Slog.d(TAG, "Not restoring user aspect ratio=" + aspectRatio + " for package=" Slog.d(TAG, "Not restoring user aspect ratio: " + aspectRatio + " for package: " + pkgName + " as it is already set to " + existingUserAspectRatio + "."); return; } mIPackageManager.setUserMinAspectRatio(pkgName, userId, aspectRatio); if (DEBUG) { Slog.d(TAG, "Restored user aspect ratio=" + aspectRatio + " for package=" + pkgName); } Slog.d(TAG, "Restored user aspect ratio: " + aspectRatio + " for package: " + pkgName); } catch (Exception e) { Slog.e(TAG, "Could not restore user aspect ratio for package " + pkgName, e); } Loading
services/core/java/com/android/server/pm/PackageManagerService.java +3 −0 Original line number Diff line number Diff line Loading @@ -6588,6 +6588,9 @@ public class PackageManagerService implements PackageSender, TestUtilityService .getPackageStateForInstalledAndFiltered(packageName, callingUid, userId); if (packageState == null) { if (com.android.window.flags.Flags.restoreUserAspectRatioSettingsUsingService()) { Slog.d(TAG, "Package: " + packageName + " not yet installed. " + "Scheduling aspect ratio update upon install, for aspect ratio: " + aspectRatio); // Pass along the request to `AppWindowLayoutSettingsService`, which will retry // to set the user aspect ratio after the package has been installed. final AppWindowLayoutSettingsService appWindowLayoutSettingsService = Loading