[3/n] Pre-select fullscreen option if overridden

Settings > Apps > Aspect ratio (experimental)

Pre-select the fullscreen option if all are true:
- device manufacturer has overridden app to fullscreen
- app has not opted out of orientation override
- app has not opted out of user's fullscreen option
- user has not set any aspect ratio (USER_MIN_ASPECT_RATIO_UNSET)

"App default" will have a new value of USER_MIN_ASPECT_RATIO_APP_DEFAULT
if device manufacturer has overridden app to fullscreen, which will
behave the same as USER_MIN_ASPECT_RATIO_UNSET without the
device-applied fullscreen override.

Bug: 310816437
Test: atest UserAspectRatioDetailsTest
      atest UserAspectRatioManagerTest
      atest UserAspectRatioAppPreferenceTest
Change-Id: I6be634bb4369292687b865ce30d902540419183c
This commit is contained in:
Graciela Wissen Putri
2023-12-15 16:15:03 +00:00
parent 72d638e681
commit 480d523a0c
7 changed files with 372 additions and 96 deletions

View File

@@ -22,6 +22,7 @@ import android.content.pm.ApplicationInfo
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.content.pm.PackageManager.GET_ACTIVITIES
import android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_APP_DEFAULT
import android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_UNSET
import android.os.Build
import android.os.Bundle
@@ -139,7 +140,9 @@ class UserAspectRatioAppListModel(private val context: Context)
recordList: List<UserAspectRatioAppListItemModel>
): List<SpinnerOption> {
val hasSuggested = recordList.any { it.suggested }
val hasOverride = recordList.any { it.userOverride != USER_MIN_ASPECT_RATIO_UNSET }
val hasOverride = recordList.any {
userAspectRatioManager.isAppOverridden(it.app, it.userOverride)
}
val options = mutableListOf(SpinnerItem.All)
// Add suggested filter first as default
if (hasSuggested) options.add(0, SpinnerItem.Suggested)
@@ -187,7 +190,9 @@ class UserAspectRatioAppListModel(private val context: Context)
): Flow<List<UserAspectRatioAppListItemModel>> = recordListFlow.filterItem(
when (SpinnerItem.entries.getOrNull(option)) {
SpinnerItem.Suggested -> ({ it.canDisplay && it.suggested })
SpinnerItem.Overridden -> ({ it.userOverride != USER_MIN_ASPECT_RATIO_UNSET })
SpinnerItem.Overridden -> ({
userAspectRatioManager.isAppOverridden(it.app, it.userOverride)
})
else -> ({ it.canDisplay })
}
)
@@ -197,7 +202,7 @@ class UserAspectRatioAppListModel(private val context: Context)
val summary by remember(record.userOverride) {
flow {
emit(userAspectRatioManager.getUserMinAspectRatioEntry(record.userOverride,
record.app.packageName))
record.app.packageName, record.app.userId))
}.flowOn(Dispatchers.IO)
}.collectAsStateWithLifecycle(initialValue = stringResource(R.string.summary_placeholder))
return { summary }