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

Commit c1baf7bb authored by Cintia Martins's avatar Cintia Martins
Browse files

Quick fix in AppBindingService

Bug: 436866167
Test: atest CtsSupervisionTestCases
Flag: android.app.supervision.flags.enable_supervision_app_service
Change-Id: Iff31d4e8bc5b0505df99530e3fa7309b6a89c91a
parent f4c9858e
Loading
Loading
Loading
Loading
+22 −20
Original line number Diff line number Diff line
@@ -161,7 +161,7 @@ public class AppBindingService extends Binder {
                if (app.getClass() != appServiceFinderClass) {
                    continue;
                }
                serviceConnections.addAll(getBoundConnectionsLocked(userId, app));
                serviceConnections.addAll(getConnectionsLocked(userId, app));
            }
        }

@@ -181,30 +181,16 @@ public class AppBindingService extends Binder {
    /**
     * Get the connection bound to a specific finder or create one if it does not exist.
     */
    private List<AppServiceConnection> getBoundConnectionsLocked(int userId,
    private List<AppServiceConnection> getConnectionsLocked(int userId,
            AppServiceFinder app) {
        Set<String> targetPackages = app.getTargetPackages(userId);
        List<AppServiceConnection> connections = new ArrayList<>();
        for (String targetPackage : targetPackages) {
            AppServiceConnection conn = findConnectionLock(userId, app, targetPackage);
            if (conn == null) {
                final ServiceInfo service =
                        app.findService(userId, mIPackageManager, mConstants, targetPackage);
                if (service != null) {
                    conn =
                            new AppServiceConnection(
                                    mContext,
                                    userId,
                                    mConstants,
                                    mHandler,
                                    app,
                                    targetPackage,
                                    service.getComponentName());
                    mConnections.add(conn);
            AppServiceConnection conn = getOrCreateConnectionLocked(userId, app, targetPackage);
            if (conn != null) {
                connections.add(conn);
            }
        }
        }
        return connections;
    }

@@ -480,7 +466,7 @@ public class AppBindingService extends Binder {
    }

    @Nullable
    private AppServiceConnection findConnectionLock(
    private AppServiceConnection getOrCreateConnectionLocked(
            int userId, @NonNull AppServiceFinder target, String targetPackage) {
        for (int i = 0; i < mConnections.size(); i++) {
            final AppServiceConnection conn = mConnections.get(i);
@@ -490,6 +476,22 @@ public class AppBindingService extends Binder {
                return conn;
            }
        }

        final ServiceInfo service =
                target.findService(userId, mIPackageManager, mConstants, targetPackage);
        if (service != null) {
            final AppServiceConnection conn  =
                    new AppServiceConnection(
                            mContext,
                            userId,
                            mConstants,
                            mHandler,
                            target,
                            targetPackage,
                            service.getComponentName());
            mConnections.add(conn);
            return conn;
        }
        return null;
    }