Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e7ed9388 authored by Matt Pietal's avatar Matt Pietal Committed by Automerger Merge Worker
Browse files

Merge "Controls UI - Service processing enhancements" into rvc-dev am:...

Merge "Controls UI - Service processing enhancements" into rvc-dev am: 23717b08 am: 3a6dace9 am: 24589546

Change-Id: I58998f76a366638279632ce3637831afba9c107f
parents 92afdae9 24589546
Loading
Loading
Loading
Loading
+24 −5
Original line number Original line Diff line number Diff line
@@ -47,6 +47,7 @@ public class ServiceListing {
    private final String mIntentAction;
    private final String mIntentAction;
    private final String mPermission;
    private final String mPermission;
    private final String mNoun;
    private final String mNoun;
    private final boolean mAddDeviceLockedFlags;
    private final HashSet<ComponentName> mEnabledServices = new HashSet<>();
    private final HashSet<ComponentName> mEnabledServices = new HashSet<>();
    private final List<ServiceInfo> mServices = new ArrayList<>();
    private final List<ServiceInfo> mServices = new ArrayList<>();
    private final List<Callback> mCallbacks = new ArrayList<>();
    private final List<Callback> mCallbacks = new ArrayList<>();
@@ -54,7 +55,8 @@ public class ServiceListing {
    private boolean mListening;
    private boolean mListening;


    private ServiceListing(Context context, String tag,
    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();
        mContentResolver = context.getContentResolver();
        mContext = context;
        mContext = context;
        mTag = tag;
        mTag = tag;
@@ -62,6 +64,7 @@ public class ServiceListing {
        mIntentAction = intentAction;
        mIntentAction = intentAction;
        mPermission = permission;
        mPermission = permission;
        mNoun = noun;
        mNoun = noun;
        mAddDeviceLockedFlags = addDeviceLockedFlags;
    }
    }


    public void addCallback(Callback callback) {
    public void addCallback(Callback callback) {
@@ -125,11 +128,15 @@ public class ServiceListing {
        mServices.clear();
        mServices.clear();
        final int user = ActivityManager.getCurrentUser();
        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();
        final PackageManager pmWrapper = mContext.getPackageManager();
        List<ResolveInfo> installedServices = pmWrapper.queryIntentServicesAsUser(
        List<ResolveInfo> installedServices = pmWrapper.queryIntentServicesAsUser(
                new Intent(mIntentAction),
                new Intent(mIntentAction), flags, user);
                PackageManager.GET_SERVICES | PackageManager.GET_META_DATA,
                user);


        for (ResolveInfo resolveInfo : installedServices) {
        for (ResolveInfo resolveInfo : installedServices) {
            ServiceInfo info = resolveInfo.serviceInfo;
            ServiceInfo info = resolveInfo.serviceInfo;
@@ -186,6 +193,7 @@ public class ServiceListing {
        private String mIntentAction;
        private String mIntentAction;
        private String mPermission;
        private String mPermission;
        private String mNoun;
        private String mNoun;
        private boolean mAddDeviceLockedFlags = false;


        public Builder(Context context) {
        public Builder(Context context) {
            mContext = context;
            mContext = context;
@@ -216,8 +224,19 @@ public class ServiceListing {
            return this;
            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() {
        public ServiceListing build() {
            return new ServiceListing(mContext, mTag, mSetting, mIntentAction, mPermission, mNoun);
            return new ServiceListing(mContext, mTag, mSetting, mIntentAction, mPermission, mNoun,
                    mAddDeviceLockedFlags);
        }
        }
    }
    }
}
}
+2 −0
Original line number Original line Diff line number Diff line
@@ -149,6 +149,7 @@ class ControlsControllerImpl @Inject constructor (
            val user = intent.getIntExtra(Intent.EXTRA_USER_ID, UserHandle.USER_NULL)
            val user = intent.getIntExtra(Intent.EXTRA_USER_ID, UserHandle.USER_NULL)
            if (user == currentUserId) {
            if (user == currentUserId) {
                executor.execute {
                executor.execute {
                    Log.d(TAG, "Restore finished, storing auxiliary favorites")
                    auxiliaryPersistenceWrapper.initialize()
                    auxiliaryPersistenceWrapper.initialize()
                    listingController.removeCallback(listingCallback)
                    listingController.removeCallback(listingCallback)
                    persistenceWrapper.storeFavorites(auxiliaryPersistenceWrapper.favorites)
                    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
                // Check if something has been added or removed, if so, store the new list
                if (changed) {
                if (changed) {
                    Log.d(TAG, "Detected change in available services, storing updated favorites")
                    persistenceWrapper.storeFavorites(Favorites.getAllStructures())
                    persistenceWrapper.storeFavorites(Favorites.getAllStructures())
                }
                }
            }
            }
+17 −6
Original line number Original line Diff line number Diff line
@@ -39,6 +39,7 @@ private fun createServiceListing(context: Context): ServiceListing {
        setNoun("Controls Provider")
        setNoun("Controls Provider")
        setSetting("controls_providers")
        setSetting("controls_providers")
        setTag("controls_providers")
        setTag("controls_providers")
        setAddDeviceLockedFlags(true)
    }.build()
    }.build()
}
}


@@ -70,23 +71,32 @@ class ControlsListingControllerImpl @VisibleForTesting constructor(
        private const val TAG = "ControlsListingControllerImpl"
        private const val TAG = "ControlsListingControllerImpl"
    }
    }


    private var availableComponents = emptySet<ComponentName>()
    private var availableServices = emptyList<ServiceInfo>()
    private var availableServices = emptyList<ServiceInfo>()


    override var currentUserId = ActivityManager.getCurrentUser()
    override var currentUserId = ActivityManager.getCurrentUser()
        private set
        private set


    private val serviceListingCallback = ServiceListing.Callback {
    private val serviceListingCallback = ServiceListing.Callback {
        Log.d(TAG, "ServiceConfig reloaded")
        val newServices = it.toList()
        availableServices = it.toList()
        val newComponents =
            newServices.mapTo(mutableSetOf<ComponentName>(), { s -> s.getComponentName() })


        backgroundExecutor.execute {
        backgroundExecutor.execute {
            if (!newComponents.equals(availableComponents)) {
                Log.d(TAG, "ServiceConfig reloaded, count: ${newComponents.size}")
                availableComponents = newComponents
                availableServices = newServices
                val currentServices = getCurrentServices()
                callbacks.forEach {
                callbacks.forEach {
                it.onServicesUpdated(getCurrentServices())
                    it.onServicesUpdated(currentServices)
                }
            }
            }
        }
        }
    }
    }


    init {
    init {
        Log.d(TAG, "Initializing")
        serviceListing.addCallback(serviceListingCallback)
        serviceListing.addCallback(serviceListingCallback)
        serviceListing.setListening(true)
        serviceListing.setListening(true)
        serviceListing.reload()
        serviceListing.reload()
@@ -119,9 +129,10 @@ class ControlsListingControllerImpl @VisibleForTesting constructor(
     */
     */
    override fun addCallback(listener: ControlsListingController.ControlsListingCallback) {
    override fun addCallback(listener: ControlsListingController.ControlsListingCallback) {
        backgroundExecutor.execute {
        backgroundExecutor.execute {
            Log.d(TAG, "Subscribing callback")
            val services = getCurrentServices()
            Log.d(TAG, "Subscribing callback, service count: ${services.size}")
            callbacks.add(listener)
            callbacks.add(listener)
            listener.onServicesUpdated(getCurrentServices())
            listener.onServicesUpdated(services)
        }
        }
    }
    }