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

Commit 3496906f authored by Eugene Susla's avatar Eugene Susla
Browse files

Cleanup appop/permissions state on sms kill switch toggle

Bug: 110098858
Test: manually remove sms appops from an app, then toggle kill switch and
ensure appop switched to default
Change-Id: I17dcaab7dcef28f6ed7e2b4621d669f24aa8a7ad
parent 2f10a26a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -6156,6 +6156,7 @@ package android.rolecontrollerservice {
    method public abstract void onClearRoleHolders(@NonNull String, @NonNull android.app.role.RoleManagerCallback);
    method public abstract void onGrantDefaultRoles(@NonNull android.app.role.RoleManagerCallback);
    method public abstract void onRemoveRoleHolder(@NonNull String, @NonNull String, @NonNull android.app.role.RoleManagerCallback);
    method public abstract void onSmsKillSwitchToggled(boolean);
    field public static final String SERVICE_INTERFACE = "android.rolecontrollerservice.RoleControllerService";
  }
+2 −0
Original line number Diff line number Diff line
@@ -32,4 +32,6 @@ oneway interface IRoleControllerService {
    void onClearRoleHolders(in String roleName, in IRoleManagerCallback callback);

    void onGrantDefaultRoles(in IRoleManagerCallback callback);

    void onSmsKillSwitchToggled(boolean smsRestrictionEnabled);
}
+13 −0
Original line number Diff line number Diff line
@@ -96,6 +96,11 @@ public abstract class RoleControllerService extends Service {
                RoleControllerService.this.onGrantDefaultRoles(new RoleManagerCallbackDelegate(
                        callback));
            }

            @Override
            public void onSmsKillSwitchToggled(boolean smsRestrictionEnabled) {
                RoleControllerService.this.onSmsKillSwitchToggled(smsRestrictionEnabled);
            }
        };
    }

@@ -140,6 +145,14 @@ public abstract class RoleControllerService extends Service {
    public abstract void onClearRoleHolders(@NonNull String roleName,
            @NonNull RoleManagerCallback callback);

    /**
     * Cleanup appop/permissions state in response to sms kill switch toggle
     *
     * @param smsRestrictionEnabled whether kill switch was turned on
     */
    //STOPSHIP: remove this api before shipping a final version
    public abstract void onSmsKillSwitchToggled(boolean smsRestrictionEnabled);

    /**
     * Called by system to grant default permissions and roles.
     * <p>
+14 −0
Original line number Diff line number Diff line
@@ -101,6 +101,20 @@ public class RemoteRoleControllerService {
                callback));
    }

    /**
     * @see RoleControllerService#onSmsKillSwitchToggled(boolean)
     */
    public void onSmsKillSwitchToggled(boolean smsRestrictionEnabled) {
        mConnection.enqueueCall(new Connection.Call(
                (s, cb) -> s.onSmsKillSwitchToggled(smsRestrictionEnabled),
                new IRoleManagerCallback.Default() {
                    @Override
                    public void onFailure() {
                        Slog.e(LOG_TAG, "Failed onSmsKillSwitchToggled");
                    }
                }));
    }

    private static final class Connection implements ServiceConnection {

        private static final long UNBIND_DELAY_MILLIS = 15 * 1000;
+15 −0
Original line number Diff line number Diff line
@@ -38,7 +38,9 @@ import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.PackageManagerInternal;
import android.content.pm.Signature;
import android.database.ContentObserver;
import android.database.CursorWindow;
import android.net.Uri;
import android.os.Binder;
import android.os.Bundle;
import android.os.Handler;
@@ -49,6 +51,7 @@ import android.os.ResultReceiver;
import android.os.ShellCallback;
import android.os.UserHandle;
import android.os.UserManagerInternal;
import android.provider.Settings;
import android.service.sms.FinancialSmsService;
import android.telephony.IFinancialSmsCallback;
import android.text.TextUtils;
@@ -185,6 +188,18 @@ public class RoleManagerService extends SystemService implements RoleUserState.C
                performInitialGrantsIfNecessary(userId);
            }
        }, UserHandle.SYSTEM, intentFilter, null /* broadcastPermission */, null /* handler */);

        getContext().getContentResolver().registerContentObserver(
                Settings.Global.getUriFor(Settings.Global.SMS_ACCESS_RESTRICTION_ENABLED), false,
                new ContentObserver(getContext().getMainThreadHandler()) {
                    @Override
                    public void onChange(boolean selfChange, Uri uri, int userId) {
                        getOrCreateControllerService(userId).onSmsKillSwitchToggled(
                                Settings.Global.getInt(
                                        getContext().getContentResolver(),
                                        Settings.Global.SMS_ACCESS_RESTRICTION_ENABLED, 0) == 1);
                    }
                }, UserHandle.USER_ALL);
    }

    @Override