Merge "Controls UI - Service processing enhancements" into rvc-dev
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user