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

Commit 113f42f3 authored by Darrell Shi's avatar Darrell Shi
Browse files

Enable configurable bind service flags

Currently, the ServiceWatcherImpl uses default flags when binding its
service. This change enables the client to configure these flags.

Bug: 375236794
Test: verified with ag/30025549
Flag: EXEMPT does not impact current usage
Change-Id: I9b03011b4f3a4767a81a4650d04cc69f172f0845
parent 616820a4
Loading
Loading
Loading
Loading
+21 −2
Original line number Diff line number Diff line
@@ -16,6 +16,10 @@

package com.android.server.servicewatcher;

import static android.content.Context.BIND_AUTO_CREATE;
import static android.content.Context.BIND_NOT_FOREGROUND;
import static android.content.Context.BIND_NOT_VISIBLE;

import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.content.ComponentName;
@@ -146,6 +150,10 @@ public interface ServiceWatcher {
        protected final @Nullable String mAction;
        protected final int mUid;
        protected final ComponentName mComponentName;
        private final int mFlags;

        private static final int DEFAULT_FLAGS =
                BIND_AUTO_CREATE | BIND_NOT_FOREGROUND | BIND_NOT_VISIBLE;

        protected BoundServiceInfo(String action, ResolveInfo resolveInfo) {
            this(action, resolveInfo.serviceInfo.applicationInfo.uid,
@@ -153,9 +161,14 @@ public interface ServiceWatcher {
        }

        protected BoundServiceInfo(String action, int uid, ComponentName componentName) {
            this(action, uid, componentName, DEFAULT_FLAGS);
        }

        protected BoundServiceInfo(String action, int uid, ComponentName componentName, int flags) {
            mAction = action;
            mUid = uid;
            mComponentName = Objects.requireNonNull(componentName);
            mFlags = flags;
        }

        /** Returns the action associated with this bound service. */
@@ -173,6 +186,11 @@ public interface ServiceWatcher {
            return UserHandle.getUserId(mUid);
        }

        /** Returns flags used when binding the service. */
        public int getFlags() {
            return mFlags;
        }

        @Override
        public final boolean equals(Object o) {
            if (this == o) {
@@ -185,12 +203,13 @@ public interface ServiceWatcher {
            BoundServiceInfo that = (BoundServiceInfo) o;
            return mUid == that.mUid
                    && Objects.equals(mAction, that.mAction)
                    && mComponentName.equals(that.mComponentName);
                    && mComponentName.equals(that.mComponentName)
                    && mFlags == that.mFlags;
        }

        @Override
        public final int hashCode() {
            return Objects.hash(mAction, mUid, mComponentName);
            return Objects.hash(mAction, mUid, mComponentName, mFlags);
        }

        @Override
+1 −5
Original line number Diff line number Diff line
@@ -16,10 +16,6 @@

package com.android.server.servicewatcher;

import static android.content.Context.BIND_AUTO_CREATE;
import static android.content.Context.BIND_NOT_FOREGROUND;
import static android.content.Context.BIND_NOT_VISIBLE;

import android.annotation.Nullable;
import android.content.ComponentName;
import android.content.Context;
@@ -214,7 +210,7 @@ class ServiceWatcherImpl<TBoundServiceInfo extends BoundServiceInfo> implements
                    mBoundServiceInfo.getComponentName());
            try {
                if (!mContext.bindServiceAsUser(bindIntent, this,
                        BIND_AUTO_CREATE | BIND_NOT_FOREGROUND | BIND_NOT_VISIBLE,
                        mBoundServiceInfo.getFlags(),
                        mHandler, UserHandle.of(mBoundServiceInfo.getUserId()))) {
                    Log.e(TAG, "[" + mTag + "] unexpected bind failure - retrying later");
                    mRebinder = this::bind;