Merge changes from topic "controls_config" into rvc-dev
* changes: Controls UI - Allow seeding for multiple apps Controls UI - Support seeding for up to 6 structures
This commit is contained in:
committed by
Android (Google) Code Review
commit
61d46be2c2
@@ -98,9 +98,12 @@ public abstract class ControlsProviderService extends Service {
|
||||
*
|
||||
* The service may be asked to provide a small number of recommended controls, in
|
||||
* order to suggest some controls to the user for favoriting. The controls shall be built using
|
||||
* the stateless builder {@link Control.StatelessBuilder}. The number of controls requested
|
||||
* through {@link Subscription#request} will be limited. Call {@link Subscriber#onComplete}
|
||||
* when done, or {@link Subscriber#onError} for error scenarios.
|
||||
* the stateless builder {@link Control.StatelessBuilder}. The total number of controls
|
||||
* requested through {@link Subscription#request} will be restricted to a maximum. Within this
|
||||
* larger limit, only 6 controls per structure will be loaded. Therefore, it is advisable to
|
||||
* seed multiple structures if they exist. Any control sent over this limit will be discarded.
|
||||
* Call {@link Subscriber#onComplete} when done, or {@link Subscriber#onError} for error
|
||||
* scenarios.
|
||||
*/
|
||||
@Nullable
|
||||
public Publisher<Control> createPublisherForSuggested() {
|
||||
|
||||
@@ -540,10 +540,10 @@
|
||||
<!-- Respect drawable/rounded.xml intrinsic size for multiple radius corner path customization -->
|
||||
<bool name="config_roundedCornerMultipleRadius">false</bool>
|
||||
|
||||
<!-- Controls can query a preferred application for limited number of suggested controls.
|
||||
This config value should contain the package name of that preferred application.
|
||||
<!-- Controls can query 2 preferred applications for limited number of suggested controls.
|
||||
This config value should contain a list of package names of thoses preferred applications.
|
||||
-->
|
||||
<string translatable="false" name="config_controlsPreferredPackage"></string>
|
||||
<string-array translatable="false" name="config_controlsPreferredPackages" />
|
||||
|
||||
<!-- Max number of columns for quick controls area -->
|
||||
<integer name="controls_max_columns">2</integer>
|
||||
|
||||
@@ -46,7 +46,9 @@ open class ControlsBindingControllerImpl @Inject constructor(
|
||||
companion object {
|
||||
private const val TAG = "ControlsBindingControllerImpl"
|
||||
private const val MAX_CONTROLS_REQUEST = 100000L
|
||||
private const val SUGGESTED_CONTROLS_REQUEST = 6L
|
||||
private const val SUGGESTED_STRUCTURES = 6L
|
||||
private const val SUGGESTED_CONTROLS_REQUEST =
|
||||
ControlsControllerImpl.SUGGESTED_CONTROLS_PER_STRUCTURE * SUGGESTED_STRUCTURES
|
||||
}
|
||||
|
||||
private var currentUser = UserHandle.of(ActivityManager.getCurrentUser())
|
||||
|
||||
@@ -114,12 +114,12 @@ interface ControlsController : UserAwareController {
|
||||
/**
|
||||
* Send a request to seed favorites into the persisted XML file
|
||||
*
|
||||
* @param componentName the component to seed controls from
|
||||
* @param callback true if the favorites were persisted
|
||||
* @param componentNames the list of components to seed controls from
|
||||
* @param callback one [SeedResponse] per componentName
|
||||
*/
|
||||
fun seedFavoritesForComponent(
|
||||
componentName: ComponentName,
|
||||
callback: Consumer<Boolean>
|
||||
fun seedFavoritesForComponents(
|
||||
componentNames: List<ComponentName>,
|
||||
callback: Consumer<SeedResponse>
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -235,3 +235,5 @@ fun createLoadDataObject(
|
||||
override val errorOnLoad = error
|
||||
}
|
||||
}
|
||||
|
||||
data class SeedResponse(val packageName: String, val accepted: Boolean)
|
||||
|
||||
@@ -72,6 +72,7 @@ class ControlsControllerImpl @Inject constructor (
|
||||
private const val USER_CHANGE_RETRY_DELAY = 500L // ms
|
||||
private const val DEFAULT_ENABLED = 1
|
||||
private const val PERMISSION_SELF = "com.android.systemui.permission.SELF"
|
||||
const val SUGGESTED_CONTROLS_PER_STRUCTURE = 6
|
||||
|
||||
private fun isAvailable(userId: Int, cr: ContentResolver) = Settings.Secure.getIntForUser(
|
||||
cr, CONTROLS_AVAILABLE, DEFAULT_ENABLED, userId) != 0
|
||||
@@ -361,29 +362,47 @@ class ControlsControllerImpl @Inject constructor (
|
||||
return true
|
||||
}
|
||||
|
||||
override fun seedFavoritesForComponent(
|
||||
componentName: ComponentName,
|
||||
callback: Consumer<Boolean>
|
||||
override fun seedFavoritesForComponents(
|
||||
componentNames: List<ComponentName>,
|
||||
callback: Consumer<SeedResponse>
|
||||
) {
|
||||
if (seedingInProgress) return
|
||||
if (seedingInProgress || componentNames.isEmpty()) return
|
||||
|
||||
Log.i(TAG, "Beginning request to seed favorites for: $componentName")
|
||||
if (!confirmAvailability()) {
|
||||
if (userChanging) {
|
||||
// Try again later, userChanging should not last forever. If so, we have bigger
|
||||
// problems. This will return a runnable that allows to cancel the delayed version,
|
||||
// it will not be able to cancel the load if
|
||||
executor.executeDelayed(
|
||||
{ seedFavoritesForComponent(componentName, callback) },
|
||||
{ seedFavoritesForComponents(componentNames, callback) },
|
||||
USER_CHANGE_RETRY_DELAY,
|
||||
TimeUnit.MILLISECONDS
|
||||
)
|
||||
} else {
|
||||
callback.accept(false)
|
||||
componentNames.forEach {
|
||||
callback.accept(SeedResponse(it.packageName, false))
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
seedingInProgress = true
|
||||
startSeeding(componentNames, callback, false)
|
||||
}
|
||||
|
||||
private fun startSeeding(
|
||||
remainingComponentNames: List<ComponentName>,
|
||||
callback: Consumer<SeedResponse>,
|
||||
didAnyFail: Boolean
|
||||
) {
|
||||
if (remainingComponentNames.isEmpty()) {
|
||||
endSeedingCall(!didAnyFail)
|
||||
return
|
||||
}
|
||||
|
||||
val componentName = remainingComponentNames[0]
|
||||
Log.d(TAG, "Beginning request to seed favorites for: $componentName")
|
||||
|
||||
val remaining = remainingComponentNames.drop(1)
|
||||
bindingController.bindAndLoadSuggested(
|
||||
componentName,
|
||||
object : ControlsBindingController.LoadCallback {
|
||||
@@ -396,9 +415,11 @@ class ControlsControllerImpl @Inject constructor (
|
||||
val structure = it.structure ?: ""
|
||||
val list = structureToControls.get(structure)
|
||||
?: mutableListOf<ControlInfo>()
|
||||
list.add(
|
||||
ControlInfo(it.controlId, it.title, it.subtitle, it.deviceType))
|
||||
structureToControls.put(structure, list)
|
||||
if (list.size < SUGGESTED_CONTROLS_PER_STRUCTURE) {
|
||||
list.add(
|
||||
ControlInfo(it.controlId, it.title, it.subtitle, it.deviceType))
|
||||
structureToControls.put(structure, list)
|
||||
}
|
||||
}
|
||||
|
||||
structureToControls.forEach {
|
||||
@@ -407,16 +428,16 @@ class ControlsControllerImpl @Inject constructor (
|
||||
}
|
||||
|
||||
persistenceWrapper.storeFavorites(Favorites.getAllStructures())
|
||||
callback.accept(true)
|
||||
endSeedingCall(true)
|
||||
callback.accept(SeedResponse(componentName.packageName, true))
|
||||
startSeeding(remaining, callback, didAnyFail)
|
||||
}
|
||||
}
|
||||
|
||||
override fun error(message: String) {
|
||||
Log.e(TAG, "Unable to seed favorites: $message")
|
||||
executor.execute {
|
||||
callback.accept(false)
|
||||
endSeedingCall(false)
|
||||
callback.accept(SeedResponse(componentName.packageName, false))
|
||||
startSeeding(remaining, callback, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -328,7 +328,7 @@ class ControlsUiControllerImpl @Inject constructor (
|
||||
val userContext = context.createContextAsUser(userHandle, 0)
|
||||
val prefs = userContext.getSharedPreferences(
|
||||
"controls_prefs", Context.MODE_PRIVATE)
|
||||
prefs.edit().putBoolean("ControlsSeedingCompleted", false).apply()
|
||||
prefs.edit().remove("SeedingCompleted").apply()
|
||||
controlsController.get().resetFavorites()
|
||||
dialog.dismiss()
|
||||
context.sendBroadcast(Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS))
|
||||
|
||||
@@ -139,8 +139,11 @@ import com.android.systemui.util.RingerModeTracker;
|
||||
import com.android.systemui.util.leak.RotationUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -180,8 +183,9 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
|
||||
static final String GLOBAL_ACTION_KEY_EMERGENCY = "emergency";
|
||||
static final String GLOBAL_ACTION_KEY_SCREENSHOT = "screenshot";
|
||||
|
||||
private static final String PREFS_CONTROLS_SEEDING_COMPLETED = "ControlsSeedingCompleted";
|
||||
private static final String PREFS_CONTROLS_SEEDING_COMPLETED = "SeedingCompleted";
|
||||
private static final String PREFS_CONTROLS_FILE = "controls_prefs";
|
||||
private static final int SEEDING_MAX = 2;
|
||||
|
||||
private final Context mContext;
|
||||
private final GlobalActionsManager mWindowManagerFuncs;
|
||||
@@ -409,47 +413,55 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* See if any available control service providers match one of the preferred components. If
|
||||
* they do, and there are no current favorites for that component, query the preferred
|
||||
* component for a limited number of suggested controls.
|
||||
*/
|
||||
private void seedFavorites() {
|
||||
if (!mControlsControllerOptional.isPresent()) return;
|
||||
if (mControlsServiceInfos.isEmpty()
|
||||
|| mControlsControllerOptional.get().getFavorites().size() > 0) {
|
||||
if (!mControlsControllerOptional.isPresent()
|
||||
|| mControlsServiceInfos.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Need to be user-specific with the context to make sure we read the correct prefs
|
||||
String[] preferredControlsPackages = mContext.getResources()
|
||||
.getStringArray(com.android.systemui.R.array.config_controlsPreferredPackages);
|
||||
|
||||
SharedPreferences prefs = mCurrentUserContextTracker.getCurrentUserContext()
|
||||
.getSharedPreferences(PREFS_CONTROLS_FILE, Context.MODE_PRIVATE);
|
||||
if (prefs.getBoolean(PREFS_CONTROLS_SEEDING_COMPLETED, false)) {
|
||||
return;
|
||||
}
|
||||
Set<String> seededPackages = prefs.getStringSet(PREFS_CONTROLS_SEEDING_COMPLETED,
|
||||
Collections.emptySet());
|
||||
|
||||
/*
|
||||
* See if any service providers match the preferred component. If they do,
|
||||
* and there are no current favorites, and we haven't successfully loaded favorites to
|
||||
* date, query the preferred component for a limited number of suggested controls.
|
||||
*/
|
||||
String preferredControlsPackage = mContext.getResources()
|
||||
.getString(com.android.systemui.R.string.config_controlsPreferredPackage);
|
||||
|
||||
ComponentName preferredComponent = null;
|
||||
List<ComponentName> componentsToSeed = new ArrayList<>();
|
||||
for (ControlsServiceInfo info : mControlsServiceInfos) {
|
||||
if (info.componentName.getPackageName().equals(preferredControlsPackage)) {
|
||||
preferredComponent = info.componentName;
|
||||
break;
|
||||
String pkg = info.componentName.getPackageName();
|
||||
if (seededPackages.contains(pkg)
|
||||
|| mControlsControllerOptional.get().countFavoritesForComponent(
|
||||
info.componentName) > 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int i = 0; i < Math.min(SEEDING_MAX, preferredControlsPackages.length); i++) {
|
||||
if (pkg.equals(preferredControlsPackages[i])) {
|
||||
componentsToSeed.add(info.componentName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (preferredComponent == null) {
|
||||
Log.i(TAG, "Controls seeding: No preferred component has been set, will not seed");
|
||||
prefs.edit().putBoolean(PREFS_CONTROLS_SEEDING_COMPLETED, true).apply();
|
||||
return;
|
||||
}
|
||||
if (componentsToSeed.isEmpty()) return;
|
||||
|
||||
mControlsControllerOptional.get().seedFavoritesForComponent(
|
||||
preferredComponent,
|
||||
(accepted) -> {
|
||||
Log.i(TAG, "Controls seeded: " + accepted);
|
||||
prefs.edit().putBoolean(PREFS_CONTROLS_SEEDING_COMPLETED, accepted).apply();
|
||||
mControlsControllerOptional.get().seedFavoritesForComponents(
|
||||
componentsToSeed,
|
||||
(response) -> {
|
||||
Log.d(TAG, "Controls seeded: " + response);
|
||||
Set<String> completedPkgs = prefs.getStringSet(PREFS_CONTROLS_SEEDING_COMPLETED,
|
||||
new HashSet<String>());
|
||||
if (response.getAccepted()) {
|
||||
completedPkgs.add(response.getPackageName());
|
||||
prefs.edit().putStringSet(PREFS_CONTROLS_SEEDING_COMPLETED,
|
||||
completedPkgs).apply();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -89,6 +89,9 @@ class ControlsControllerImplTest : SysuiTestCase() {
|
||||
@Captor
|
||||
private lateinit var controlLoadCallbackCaptor:
|
||||
ArgumentCaptor<ControlsBindingController.LoadCallback>
|
||||
@Captor
|
||||
private lateinit var controlLoadCallbackCaptor2:
|
||||
ArgumentCaptor<ControlsBindingController.LoadCallback>
|
||||
|
||||
@Captor
|
||||
private lateinit var broadcastReceiverCaptor: ArgumentCaptor<BroadcastReceiver>
|
||||
@@ -797,33 +800,63 @@ class ControlsControllerImplTest : SysuiTestCase() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSeedFavoritesForComponent() {
|
||||
var succeeded = false
|
||||
val control = statelessBuilderFromInfo(TEST_CONTROL_INFO, TEST_STRUCTURE_INFO.structure)
|
||||
.build()
|
||||
fun testSeedFavoritesForComponentsWithLimit() {
|
||||
var responses = mutableListOf<SeedResponse>()
|
||||
|
||||
controller.seedFavoritesForComponent(TEST_COMPONENT, Consumer { accepted ->
|
||||
succeeded = accepted
|
||||
val controls1 = mutableListOf<Control>()
|
||||
for (i in 1..10) {
|
||||
controls1.add(statelessBuilderFromInfo(ControlInfo("id1:$i", TEST_CONTROL_TITLE,
|
||||
TEST_CONTROL_SUBTITLE, TEST_DEVICE_TYPE), "testStructure").build())
|
||||
}
|
||||
val controls2 = mutableListOf<Control>()
|
||||
for (i in 1..3) {
|
||||
controls2.add(statelessBuilderFromInfo(ControlInfo("id2:$i", TEST_CONTROL_TITLE,
|
||||
TEST_CONTROL_SUBTITLE, TEST_DEVICE_TYPE), "testStructure2").build())
|
||||
}
|
||||
controller.seedFavoritesForComponents(listOf(TEST_COMPONENT, TEST_COMPONENT_2), Consumer {
|
||||
resp -> responses.add(resp)
|
||||
})
|
||||
|
||||
verify(bindingController).bindAndLoadSuggested(eq(TEST_COMPONENT),
|
||||
capture(controlLoadCallbackCaptor))
|
||||
|
||||
controlLoadCallbackCaptor.value.accept(listOf(control))
|
||||
|
||||
controlLoadCallbackCaptor.value.accept(controls1)
|
||||
delayableExecutor.runAllReady()
|
||||
|
||||
assertEquals(listOf(TEST_STRUCTURE_INFO),
|
||||
controller.getFavoritesForComponent(TEST_COMPONENT))
|
||||
assertTrue(succeeded)
|
||||
verify(bindingController).bindAndLoadSuggested(eq(TEST_COMPONENT_2),
|
||||
capture(controlLoadCallbackCaptor2))
|
||||
controlLoadCallbackCaptor2.value.accept(controls2)
|
||||
delayableExecutor.runAllReady()
|
||||
|
||||
// COMPONENT 1
|
||||
val structureInfo = controller.getFavoritesForComponent(TEST_COMPONENT)[0]
|
||||
assertEquals(structureInfo.controls.size,
|
||||
ControlsControllerImpl.SUGGESTED_CONTROLS_PER_STRUCTURE)
|
||||
|
||||
var i = 1
|
||||
structureInfo.controls.forEach {
|
||||
assertEquals(it.controlId, "id1:$i")
|
||||
i++
|
||||
}
|
||||
assertEquals(SeedResponse(TEST_COMPONENT.packageName, true), responses[0])
|
||||
|
||||
// COMPONENT 2
|
||||
val structureInfo2 = controller.getFavoritesForComponent(TEST_COMPONENT_2)[0]
|
||||
assertEquals(structureInfo2.controls.size, 3)
|
||||
|
||||
i = 1
|
||||
structureInfo2.controls.forEach {
|
||||
assertEquals(it.controlId, "id2:$i")
|
||||
i++
|
||||
}
|
||||
assertEquals(SeedResponse(TEST_COMPONENT.packageName, true), responses[1])
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSeedFavoritesForComponent_error() {
|
||||
var succeeded = false
|
||||
fun testSeedFavoritesForComponents_error() {
|
||||
var response: SeedResponse? = null
|
||||
|
||||
controller.seedFavoritesForComponent(TEST_COMPONENT, Consumer { accepted ->
|
||||
succeeded = accepted
|
||||
controller.seedFavoritesForComponents(listOf(TEST_COMPONENT), Consumer { resp ->
|
||||
response = resp
|
||||
})
|
||||
|
||||
verify(bindingController).bindAndLoadSuggested(eq(TEST_COMPONENT),
|
||||
@@ -834,18 +867,18 @@ class ControlsControllerImplTest : SysuiTestCase() {
|
||||
delayableExecutor.runAllReady()
|
||||
|
||||
assertEquals(listOf<StructureInfo>(), controller.getFavoritesForComponent(TEST_COMPONENT))
|
||||
assertFalse(succeeded)
|
||||
assertEquals(SeedResponse(TEST_COMPONENT.packageName, false), response)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSeedFavoritesForComponent_inProgressCallback() {
|
||||
var succeeded = false
|
||||
fun testSeedFavoritesForComponents_inProgressCallback() {
|
||||
var response: SeedResponse? = null
|
||||
var seeded = false
|
||||
val control = statelessBuilderFromInfo(TEST_CONTROL_INFO, TEST_STRUCTURE_INFO.structure)
|
||||
.build()
|
||||
|
||||
controller.seedFavoritesForComponent(TEST_COMPONENT, Consumer { accepted ->
|
||||
succeeded = accepted
|
||||
controller.seedFavoritesForComponents(listOf(TEST_COMPONENT), Consumer { resp ->
|
||||
response = resp
|
||||
})
|
||||
|
||||
verify(bindingController).bindAndLoadSuggested(eq(TEST_COMPONENT),
|
||||
@@ -860,7 +893,7 @@ class ControlsControllerImplTest : SysuiTestCase() {
|
||||
|
||||
assertEquals(listOf(TEST_STRUCTURE_INFO),
|
||||
controller.getFavoritesForComponent(TEST_COMPONENT))
|
||||
assertTrue(succeeded)
|
||||
assertEquals(SeedResponse(TEST_COMPONENT.packageName, true), response)
|
||||
assertTrue(seeded)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user