diff options
| author | 2020-04-29 09:33:29 -0400 | |
|---|---|---|
| committer | 2020-04-30 11:04:31 -0400 | |
| commit | b0a9eefa00f00487bc90ece49f1c5f6f2af16535 (patch) | |
| tree | 505bd81fbba0c41b471a79a90c4cfc6c7488d7be | |
| parent | 520d7c586b593f598b0874d55c488763dd1f4c08 (diff) | |
Controls UI - Service processing enhancements
1. Add better logging around events where favorites may be altered
2. Diff the incoming services and only process if there is a indeed a
difference, which will also prevent control flashing
3. Enhance service listing to be able to get services prior to the
device unlocking after reboot
Bug: 155198365
Bug: 153448765
Bug: 152798348
Bug: 155060649
Test: reboot device, and trigger global actions before and after unlocking
Change-Id: I87295fc0842c82377424019f59fc6c4de99eeae0
3 files changed, 43 insertions, 11 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/applications/ServiceListing.java b/packages/SettingsLib/src/com/android/settingslib/applications/ServiceListing.java index 454d1dce0b2f..bd9e760acfda 100644 --- a/packages/SettingsLib/src/com/android/settingslib/applications/ServiceListing.java +++ b/packages/SettingsLib/src/com/android/settingslib/applications/ServiceListing.java @@ -47,6 +47,7 @@ public class ServiceListing { private final String mIntentAction; private final String mPermission; private final String mNoun; + private final boolean mAddDeviceLockedFlags; private final HashSet<ComponentName> mEnabledServices = new HashSet<>(); private final List<ServiceInfo> mServices = new ArrayList<>(); private final List<Callback> mCallbacks = new ArrayList<>(); @@ -54,7 +55,8 @@ public class ServiceListing { private boolean mListening; private ServiceListing(Context context, String tag, - String setting, String intentAction, String permission, String noun) { + String setting, String intentAction, String permission, String noun, + boolean addDeviceLockedFlags) { mContentResolver = context.getContentResolver(); mContext = context; mTag = tag; @@ -62,6 +64,7 @@ public class ServiceListing { mIntentAction = intentAction; mPermission = permission; mNoun = noun; + mAddDeviceLockedFlags = addDeviceLockedFlags; } public void addCallback(Callback callback) { @@ -125,11 +128,15 @@ public class ServiceListing { mServices.clear(); final int user = ActivityManager.getCurrentUser(); + int flags = PackageManager.GET_SERVICES | PackageManager.GET_META_DATA; + if (mAddDeviceLockedFlags) { + flags |= PackageManager.MATCH_DIRECT_BOOT_AWARE + | PackageManager.MATCH_DIRECT_BOOT_UNAWARE; + } + final PackageManager pmWrapper = mContext.getPackageManager(); List<ResolveInfo> installedServices = pmWrapper.queryIntentServicesAsUser( - new Intent(mIntentAction), - PackageManager.GET_SERVICES | PackageManager.GET_META_DATA, - user); + new Intent(mIntentAction), flags, user); for (ResolveInfo resolveInfo : installedServices) { ServiceInfo info = resolveInfo.serviceInfo; @@ -186,6 +193,7 @@ public class ServiceListing { private String mIntentAction; private String mPermission; private String mNoun; + private boolean mAddDeviceLockedFlags = false; public Builder(Context context) { mContext = context; @@ -216,8 +224,19 @@ public class ServiceListing { return this; } + /** + * Set to true to add support for both MATCH_DIRECT_BOOT_AWARE and + * MATCH_DIRECT_BOOT_UNAWARE flags when querying PackageManager. Required to get results + * prior to the user unlocking the device for the first time. + */ + public Builder setAddDeviceLockedFlags(boolean addDeviceLockedFlags) { + mAddDeviceLockedFlags = addDeviceLockedFlags; + return this; + } + public ServiceListing build() { - return new ServiceListing(mContext, mTag, mSetting, mIntentAction, mPermission, mNoun); + return new ServiceListing(mContext, mTag, mSetting, mIntentAction, mPermission, mNoun, + mAddDeviceLockedFlags); } } } diff --git a/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsControllerImpl.kt b/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsControllerImpl.kt index 8e88756b16fd..bbabaa4b29ed 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsControllerImpl.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsControllerImpl.kt @@ -149,6 +149,7 @@ class ControlsControllerImpl @Inject constructor ( val user = intent.getIntExtra(Intent.EXTRA_USER_ID, UserHandle.USER_NULL) if (user == currentUserId) { executor.execute { + Log.d(TAG, "Restore finished, storing auxiliary favorites") auxiliaryPersistenceWrapper.initialize() listingController.removeCallback(listingCallback) persistenceWrapper.storeFavorites(auxiliaryPersistenceWrapper.favorites) @@ -219,6 +220,7 @@ class ControlsControllerImpl @Inject constructor ( // Check if something has been added or removed, if so, store the new list if (changed) { + Log.d(TAG, "Detected change in available services, storing updated favorites") persistenceWrapper.storeFavorites(Favorites.getAllStructures()) } } diff --git a/packages/SystemUI/src/com/android/systemui/controls/management/ControlsListingControllerImpl.kt b/packages/SystemUI/src/com/android/systemui/controls/management/ControlsListingControllerImpl.kt index 94487e5a584a..3590f1f4fad8 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/management/ControlsListingControllerImpl.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/management/ControlsListingControllerImpl.kt @@ -39,6 +39,7 @@ private fun createServiceListing(context: Context): ServiceListing { setNoun("Controls Provider") setSetting("controls_providers") setTag("controls_providers") + setAddDeviceLockedFlags(true) }.build() } @@ -70,23 +71,32 @@ class ControlsListingControllerImpl @VisibleForTesting constructor( private const val TAG = "ControlsListingControllerImpl" } + private var availableComponents = emptySet<ComponentName>() private var availableServices = emptyList<ServiceInfo>() override var currentUserId = ActivityManager.getCurrentUser() private set private val serviceListingCallback = ServiceListing.Callback { - Log.d(TAG, "ServiceConfig reloaded") - availableServices = it.toList() + val newServices = it.toList() + val newComponents = + newServices.mapTo(mutableSetOf<ComponentName>(), { s -> s.getComponentName() }) backgroundExecutor.execute { - callbacks.forEach { - it.onServicesUpdated(getCurrentServices()) + if (!newComponents.equals(availableComponents)) { + Log.d(TAG, "ServiceConfig reloaded, count: ${newComponents.size}") + availableComponents = newComponents + availableServices = newServices + val currentServices = getCurrentServices() + callbacks.forEach { + it.onServicesUpdated(currentServices) + } } } } init { + Log.d(TAG, "Initializing") serviceListing.addCallback(serviceListingCallback) serviceListing.setListening(true) serviceListing.reload() @@ -119,9 +129,10 @@ class ControlsListingControllerImpl @VisibleForTesting constructor( */ override fun addCallback(listener: ControlsListingController.ControlsListingCallback) { backgroundExecutor.execute { - Log.d(TAG, "Subscribing callback") + val services = getCurrentServices() + Log.d(TAG, "Subscribing callback, service count: ${services.size}") callbacks.add(listener) - listener.onServicesUpdated(getCurrentServices()) + listener.onServicesUpdated(services) } } |