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

Commit 11b13adf authored by Tianjie Xu's avatar Tianjie Xu Committed by Gerrit Code Review
Browse files

Merge "Add shell command to set package"

parents eda5da6b 6a0d50dd
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -357,6 +357,7 @@
    <uses-permission android:name="android.permission.BIND_VOICE_INTERACTION" />
    <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
    <uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
    <uses-permission android:name="android.permission.BIND_RESUME_ON_REBOOT_SERVICE" />

    <application android:label="@string/app_label"
                android:theme="@android:style/Theme.DeviceDefault.DayNight"
+9 −2
Original line number Diff line number Diff line
@@ -2381,10 +2381,17 @@ public class LockSettingsService extends ILockSettings.Stub {
    public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
            String[] args, ShellCallback callback, ResultReceiver resultReceiver) {
        enforceShell();
        final int origPid = Binder.getCallingPid();
        final int origUid = Binder.getCallingUid();

        // The original identity is an opaque integer.
        final long origId = Binder.clearCallingIdentity();
        Slog.e(TAG, "Caller pid " + origPid + " Caller uid " + origUid);
        try {
            (new LockSettingsShellCommand(new LockPatternUtils(mContext))).exec(
                    this, in, out, err, args, callback, resultReceiver);
            final LockSettingsShellCommand command =
                    new LockSettingsShellCommand(new LockPatternUtils(mContext), mContext, origPid,
                            origUid);
            command.exec(this, in, out, err, args, callback, resultReceiver);
        } finally {
            Binder.restoreCallingIdentity(origId);
        }
+32 −1
Original line number Diff line number Diff line
@@ -23,8 +23,11 @@ import static com.android.internal.widget.LockPatternUtils.CREDENTIAL_TYPE_PATTE

import android.app.ActivityManager;
import android.app.admin.PasswordMetrics;
import android.content.Context;
import android.os.ShellCommand;
import android.os.SystemProperties;
import android.text.TextUtils;
import android.util.Slog;

import com.android.internal.widget.LockPatternUtils;
import com.android.internal.widget.LockPatternUtils.RequestThrottledException;
@@ -45,15 +48,25 @@ class LockSettingsShellCommand extends ShellCommand {
    private static final String COMMAND_VERIFY = "verify";
    private static final String COMMAND_GET_DISABLED = "get-disabled";
    private static final String COMMAND_REMOVE_CACHE = "remove-cache";
    private static final String COMMAND_SET_ROR_PROVIDER_PACKAGE =
            "set-resume-on-reboot-provider-package";
    private static final String COMMAND_HELP = "help";

    private int mCurrentUserId;
    private final LockPatternUtils mLockPatternUtils;
    private final Context mContext;
    private final int mCallingPid;
    private final int mCallingUid;

    private String mOld = "";
    private String mNew = "";

    LockSettingsShellCommand(LockPatternUtils lockPatternUtils) {
    LockSettingsShellCommand(LockPatternUtils lockPatternUtils, Context context, int callingPid,
            int callingUid) {
        mLockPatternUtils = lockPatternUtils;
        mCallingPid = callingPid;
        mCallingUid = callingUid;
        mContext = context;
    }

    @Override
@@ -70,6 +83,7 @@ class LockSettingsShellCommand extends ShellCommand {
                    case COMMAND_HELP:
                    case COMMAND_GET_DISABLED:
                    case COMMAND_SET_DISABLED:
                    case COMMAND_SET_ROR_PROVIDER_PACKAGE:
                        break;
                    default:
                        getErrPrintWriter().println(
@@ -82,6 +96,9 @@ class LockSettingsShellCommand extends ShellCommand {
                case COMMAND_REMOVE_CACHE:
                    runRemoveCache();
                    return 0;
                case COMMAND_SET_ROR_PROVIDER_PACKAGE:
                    runSetResumeOnRebootProviderPackage();
                    return 0;
                case COMMAND_HELP:
                    onHelp();
                    return 0;
@@ -172,6 +189,9 @@ class LockSettingsShellCommand extends ShellCommand {
            pw.println("");
            pw.println("  remove-cache [--user USER_ID]");
            pw.println("    Removes cached unified challenge for the managed profile.");
            pw.println("  set-resume-on-reboot-provider-package <package_name>");
            pw.println("    Sets the package name for server based resume on reboot service "
                    + "provider.");
            pw.println("");
        }
    }
@@ -258,6 +278,17 @@ class LockSettingsShellCommand extends ShellCommand {
        return true;
    }

    private boolean runSetResumeOnRebootProviderPackage() {
        final String packageName = mNew;
        String name = ResumeOnRebootServiceProvider.PROP_ROR_PROVIDER_PACKAGE;
        Slog.i(TAG, "Setting " +  name + " to " + packageName);

        mContext.enforcePermission(android.Manifest.permission.BIND_RESUME_ON_REBOOT_SERVICE,
                mCallingPid, mCallingUid, TAG);
        SystemProperties.set(name, packageName);
        return true;
    }

    private boolean runClear() {
        LockscreenCredential none = LockscreenCredential.createNone();
        if (!isNewCredentialSufficient(none)) {
+16 −4
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.os.IBinder;
import android.os.ParcelableException;
import android.os.RemoteCallback;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.provider.DeviceConfig;
import android.service.resumeonreboot.IResumeOnRebootService;
@@ -55,6 +56,10 @@ public class ResumeOnRebootServiceProvider {
            Manifest.permission.BIND_RESUME_ON_REBOOT_SERVICE;
    private static final String TAG = "ResumeOnRebootServiceProvider";

    // The system property name that overrides the default service provider package name.
    static final String PROP_ROR_PROVIDER_PACKAGE =
            "persist.sys.resume_on_reboot_provider_package";

    private final Context mContext;
    private final PackageManager mPackageManager;

@@ -72,12 +77,19 @@ public class ResumeOnRebootServiceProvider {
    private ServiceInfo resolveService() {
        Intent intent = new Intent();
        intent.setAction(ResumeOnRebootService.SERVICE_INTERFACE);
        int queryFlag = PackageManager.GET_SERVICES;
        String testAppName = SystemProperties.get(PROP_ROR_PROVIDER_PACKAGE, "");
        if (!testAppName.isEmpty()) {
            Slog.i(TAG, "Using test app: " + testAppName);
            intent.setPackage(testAppName);
        } else {
            queryFlag |= PackageManager.MATCH_SYSTEM_ONLY;
            if (PROVIDER_PACKAGE != null && !PROVIDER_PACKAGE.equals("")) {
                intent.setPackage(PROVIDER_PACKAGE);
            }
        }

        List<ResolveInfo> resolvedIntents =
                mPackageManager.queryIntentServices(intent, PackageManager.MATCH_SYSTEM_ONLY);
        List<ResolveInfo> resolvedIntents = mPackageManager.queryIntentServices(intent, queryFlag);
        for (ResolveInfo resolvedInfo : resolvedIntents) {
            if (resolvedInfo.serviceInfo != null
                    && PROVIDER_REQUIRED_PERMISSION.equals(resolvedInfo.serviceInfo.permission)) {
+3 −1
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import android.content.Context;
import android.os.Binder;
import android.os.Handler;
import android.os.Looper;
import android.os.Process;
import android.os.ResultReceiver;
import android.os.ShellCallback;
import android.platform.test.annotations.Presubmit;
@@ -86,7 +87,8 @@ public class LockSettingsShellCommandTest {
        MockitoAnnotations.initMocks(this);
        final Context context = InstrumentationRegistry.getTargetContext();
        mUserId = ActivityManager.getCurrentUser();
        mCommand = new LockSettingsShellCommand(mLockPatternUtils);
        mCommand = new LockSettingsShellCommand(mLockPatternUtils, context, 0,
                Process.SHELL_UID);
        when(mLockPatternUtils.hasSecureLockScreen()).thenReturn(true);
    }