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

Commit 839eecb2 authored by Elis Elliott's avatar Elis Elliott
Browse files

Use the context user when checking for apps subject to suspension.

Test: btest a.d.c.PersonalAppsSuspensionTest

Fixes: 309183330
Change-Id: I09b4b7fe4786e476d8ed43aede030be7f8f8721b
parent 56671376
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -55,3 +55,10 @@ flag {
  description: "Guards a bugfix that ends the credential input flow if the managed user has not stopped."
  bug: "293441361"
}

flag {
    name: "default_sms_personal_app_suspension_fix_enabled"
    namespace: "enterprise"
    description: "Exempt the default sms app of the context user for suspension when calling setPersonalAppsSuspended"
    bug: "309183330"
}
+15 −2
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server.devicepolicy;

import static android.accessibilityservice.AccessibilityServiceInfo.FEEDBACK_ALL_MASK;
import static android.app.admin.flags.Flags.defaultSmsPersonalAppSuspensionFixEnabled;

import android.accessibilityservice.AccessibilityServiceInfo;
import android.annotation.Nullable;
@@ -42,6 +43,7 @@ import android.view.accessibility.IAccessibilityManager;
import android.view.inputmethod.InputMethodInfo;

import com.android.internal.R;
import com.android.internal.telephony.SmsApplication;
import com.android.server.inputmethod.InputMethodManagerInternal;
import com.android.server.utils.Slogf;

@@ -97,7 +99,7 @@ public final class PersonalAppsSuspensionHelper {
        result.removeAll(getSystemLauncherPackages());
        result.removeAll(getAccessibilityServices());
        result.removeAll(getInputMethodPackages());
        result.remove(Telephony.Sms.getDefaultSmsPackage(mContext));
        result.remove(getDefaultSmsPackage());
        result.remove(getSettingsPackageName());

        final String[] unsuspendablePackages =
@@ -202,6 +204,17 @@ public final class PersonalAppsSuspensionHelper {
        return resolveInfos != null && !resolveInfos.isEmpty();
    }

    private String getDefaultSmsPackage() {
        //TODO(b/319449037): Unflag the following change.
        if (defaultSmsPersonalAppSuspensionFixEnabled()) {
            return SmsApplication.getDefaultSmsApplicationAsUser(
                            mContext, /*updateIfNeeded=*/ false, mContext.getUser())
                    .getPackageName();
        } else {
            return Telephony.Sms.getDefaultSmsPackage(mContext);
        }
    }


    void dump(IndentingPrintWriter pw) {
        pw.println("PersonalAppsSuspensionHelper");
@@ -212,7 +225,7 @@ public final class PersonalAppsSuspensionHelper {
        DevicePolicyManagerService.dumpApps(pw, "accessibility services",
                getAccessibilityServices());
        DevicePolicyManagerService.dumpApps(pw, "input method packages", getInputMethodPackages());
        pw.printf("SMS package: %s\n", Telephony.Sms.getDefaultSmsPackage(mContext));
        pw.printf("SMS package: %s\n", getDefaultSmsPackage());
        pw.printf("Settings package: %s\n", getSettingsPackageName());
        DevicePolicyManagerService.dumpApps(pw, "Packages subject to suspension",
                getPersonalAppsForSuspension());