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

Commit b43ee9bf authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "[CDM] Update binding flag for self-managed apps" into tm-dev am:...

Merge "[CDM] Update binding flag for self-managed apps" into tm-dev am: c4be963f am: f5b33da6 am: 60d6a31d

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18567157



Change-Id: I01959dad208cfde0dfd043a25698889fb6b82f85
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 7fe20424 60d6a31d
Loading
Loading
Loading
Loading
+3 −3
Original line number Original line Diff line number Diff line
@@ -104,10 +104,10 @@ class CompanionApplicationController {
    }
    }


    void bindCompanionApplication(@UserIdInt int userId, @NonNull String packageName,
    void bindCompanionApplication(@UserIdInt int userId, @NonNull String packageName,
            boolean bindImportant) {
            boolean isSelfManaged) {
        if (DEBUG) {
        if (DEBUG) {
            Log.i(TAG, "bind() u" + userId + "/" + packageName
            Log.i(TAG, "bind() u" + userId + "/" + packageName
                    + " important=" + bindImportant);
                    + " isSelfManaged=" + isSelfManaged);
        }
        }


        final List<ComponentName> companionServices =
        final List<ComponentName> companionServices =
@@ -130,7 +130,7 @@ class CompanionApplicationController {


            serviceConnectors = CollectionUtils.map(companionServices, componentName ->
            serviceConnectors = CollectionUtils.map(companionServices, componentName ->
                            CompanionDeviceServiceConnector.newInstance(mContext, userId,
                            CompanionDeviceServiceConnector.newInstance(mContext, userId,
                                    componentName, bindImportant));
                                    componentName, isSelfManaged));
            mBoundCompanionApplications.setValueForPackage(userId, packageName, serviceConnectors);
            mBoundCompanionApplications.setValueForPackage(userId, packageName, serviceConnectors);
        }
        }


+8 −7
Original line number Original line Diff line number Diff line
@@ -17,7 +17,7 @@
package com.android.server.companion;
package com.android.server.companion;


import static android.content.Context.BIND_ALMOST_PERCEPTIBLE;
import static android.content.Context.BIND_ALMOST_PERCEPTIBLE;
import static android.content.Context.BIND_IMPORTANT;
import static android.content.Context.BIND_TREAT_LIKE_VISIBLE_FOREGROUND_SERVICE;
import static android.os.Process.THREAD_PRIORITY_DEFAULT;
import static android.os.Process.THREAD_PRIORITY_DEFAULT;


import android.annotation.NonNull;
import android.annotation.NonNull;
@@ -61,21 +61,22 @@ class CompanionDeviceServiceConnector extends ServiceConnector.Impl<ICompanionDe
    /**
    /**
     * Create a CompanionDeviceServiceConnector instance.
     * Create a CompanionDeviceServiceConnector instance.
     *
     *
     * When bindImportant is false, the binding flag will be BIND_ALMOST_PERCEPTIBLE
     * For self-managed apps, the binding flag will be BIND_TREAT_LIKE_VISIBLE_FOREGROUND_SERVICE
     * (oom_score_adj = VISIBLE_APP_ADJ = 100).
     *
     * For non self-managed apps, the binding flag will be BIND_ALMOST_PERCEPTIBLE
     * (oom_score_adj = PERCEPTIBLE_MEDIUM_APP = 225). The target service will be treated
     * (oom_score_adj = PERCEPTIBLE_MEDIUM_APP = 225). The target service will be treated
     * as important as a perceptible app (IMPORTANCE_VISIBLE = 200), and will be unbound when
     * as important as a perceptible app (IMPORTANCE_VISIBLE = 200), and will be unbound when
     * the app is removed from task manager.
     * the app is removed from task manager.
     * When bindImportant is true, the binding flag will be BIND_IMPORTANT
     * (oom_score_adj = PERCEPTIBLE_MEDIUM_APP = -700). The target service will
     * have the highest priority to avoid being killed (IMPORTANCE_FOREGROUND = 100).
     *
     *
     * One time permission's importance level to keep session alive is
     * One time permission's importance level to keep session alive is
     * IMPORTANCE_FOREGROUND_SERVICE = 125. In order to kill the one time permission session, the
     * IMPORTANCE_FOREGROUND_SERVICE = 125. In order to kill the one time permission session, the
     * service importance level should be higher than 125.
     * service importance level should be higher than 125.
     */
     */
    static CompanionDeviceServiceConnector newInstance(@NonNull Context context,
    static CompanionDeviceServiceConnector newInstance(@NonNull Context context,
            @UserIdInt int userId, @NonNull ComponentName componentName, boolean bindImportant) {
            @UserIdInt int userId, @NonNull ComponentName componentName, boolean isSelfManaged) {
        final int bindingFlags = bindImportant ? BIND_IMPORTANT : BIND_ALMOST_PERCEPTIBLE;
        final int bindingFlags = isSelfManaged ? BIND_TREAT_LIKE_VISIBLE_FOREGROUND_SERVICE
                : BIND_ALMOST_PERCEPTIBLE;
        return new CompanionDeviceServiceConnector(context, userId, componentName, bindingFlags);
        return new CompanionDeviceServiceConnector(context, userId, componentName, bindingFlags);
    }
    }