Merge "Add shell command to set package" am: 11b13adfb7
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1560109 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: I55b5612e4b93039718e13b8ef08165f156708099
This commit is contained in:
@@ -357,6 +357,7 @@
|
|||||||
<uses-permission android:name="android.permission.BIND_VOICE_INTERACTION" />
|
<uses-permission android:name="android.permission.BIND_VOICE_INTERACTION" />
|
||||||
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
|
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
|
||||||
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
|
<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"
|
<application android:label="@string/app_label"
|
||||||
android:theme="@android:style/Theme.DeviceDefault.DayNight"
|
android:theme="@android:style/Theme.DeviceDefault.DayNight"
|
||||||
|
|||||||
@@ -2381,10 +2381,17 @@ public class LockSettingsService extends ILockSettings.Stub {
|
|||||||
public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
|
public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
|
||||||
String[] args, ShellCallback callback, ResultReceiver resultReceiver) {
|
String[] args, ShellCallback callback, ResultReceiver resultReceiver) {
|
||||||
enforceShell();
|
enforceShell();
|
||||||
|
final int origPid = Binder.getCallingPid();
|
||||||
|
final int origUid = Binder.getCallingUid();
|
||||||
|
|
||||||
|
// The original identity is an opaque integer.
|
||||||
final long origId = Binder.clearCallingIdentity();
|
final long origId = Binder.clearCallingIdentity();
|
||||||
|
Slog.e(TAG, "Caller pid " + origPid + " Caller uid " + origUid);
|
||||||
try {
|
try {
|
||||||
(new LockSettingsShellCommand(new LockPatternUtils(mContext))).exec(
|
final LockSettingsShellCommand command =
|
||||||
this, in, out, err, args, callback, resultReceiver);
|
new LockSettingsShellCommand(new LockPatternUtils(mContext), mContext, origPid,
|
||||||
|
origUid);
|
||||||
|
command.exec(this, in, out, err, args, callback, resultReceiver);
|
||||||
} finally {
|
} finally {
|
||||||
Binder.restoreCallingIdentity(origId);
|
Binder.restoreCallingIdentity(origId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,8 +23,11 @@ import static com.android.internal.widget.LockPatternUtils.CREDENTIAL_TYPE_PATTE
|
|||||||
|
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.app.admin.PasswordMetrics;
|
import android.app.admin.PasswordMetrics;
|
||||||
|
import android.content.Context;
|
||||||
import android.os.ShellCommand;
|
import android.os.ShellCommand;
|
||||||
|
import android.os.SystemProperties;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.util.Slog;
|
||||||
|
|
||||||
import com.android.internal.widget.LockPatternUtils;
|
import com.android.internal.widget.LockPatternUtils;
|
||||||
import com.android.internal.widget.LockPatternUtils.RequestThrottledException;
|
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_VERIFY = "verify";
|
||||||
private static final String COMMAND_GET_DISABLED = "get-disabled";
|
private static final String COMMAND_GET_DISABLED = "get-disabled";
|
||||||
private static final String COMMAND_REMOVE_CACHE = "remove-cache";
|
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 static final String COMMAND_HELP = "help";
|
||||||
|
|
||||||
private int mCurrentUserId;
|
private int mCurrentUserId;
|
||||||
private final LockPatternUtils mLockPatternUtils;
|
private final LockPatternUtils mLockPatternUtils;
|
||||||
|
private final Context mContext;
|
||||||
|
private final int mCallingPid;
|
||||||
|
private final int mCallingUid;
|
||||||
|
|
||||||
private String mOld = "";
|
private String mOld = "";
|
||||||
private String mNew = "";
|
private String mNew = "";
|
||||||
|
|
||||||
LockSettingsShellCommand(LockPatternUtils lockPatternUtils) {
|
LockSettingsShellCommand(LockPatternUtils lockPatternUtils, Context context, int callingPid,
|
||||||
|
int callingUid) {
|
||||||
mLockPatternUtils = lockPatternUtils;
|
mLockPatternUtils = lockPatternUtils;
|
||||||
|
mCallingPid = callingPid;
|
||||||
|
mCallingUid = callingUid;
|
||||||
|
mContext = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -70,6 +83,7 @@ class LockSettingsShellCommand extends ShellCommand {
|
|||||||
case COMMAND_HELP:
|
case COMMAND_HELP:
|
||||||
case COMMAND_GET_DISABLED:
|
case COMMAND_GET_DISABLED:
|
||||||
case COMMAND_SET_DISABLED:
|
case COMMAND_SET_DISABLED:
|
||||||
|
case COMMAND_SET_ROR_PROVIDER_PACKAGE:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
getErrPrintWriter().println(
|
getErrPrintWriter().println(
|
||||||
@@ -82,6 +96,9 @@ class LockSettingsShellCommand extends ShellCommand {
|
|||||||
case COMMAND_REMOVE_CACHE:
|
case COMMAND_REMOVE_CACHE:
|
||||||
runRemoveCache();
|
runRemoveCache();
|
||||||
return 0;
|
return 0;
|
||||||
|
case COMMAND_SET_ROR_PROVIDER_PACKAGE:
|
||||||
|
runSetResumeOnRebootProviderPackage();
|
||||||
|
return 0;
|
||||||
case COMMAND_HELP:
|
case COMMAND_HELP:
|
||||||
onHelp();
|
onHelp();
|
||||||
return 0;
|
return 0;
|
||||||
@@ -172,6 +189,9 @@ class LockSettingsShellCommand extends ShellCommand {
|
|||||||
pw.println("");
|
pw.println("");
|
||||||
pw.println(" remove-cache [--user USER_ID]");
|
pw.println(" remove-cache [--user USER_ID]");
|
||||||
pw.println(" Removes cached unified challenge for the managed profile.");
|
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("");
|
pw.println("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -258,6 +278,17 @@ class LockSettingsShellCommand extends ShellCommand {
|
|||||||
return true;
|
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() {
|
private boolean runClear() {
|
||||||
LockscreenCredential none = LockscreenCredential.createNone();
|
LockscreenCredential none = LockscreenCredential.createNone();
|
||||||
if (!isNewCredentialSufficient(none)) {
|
if (!isNewCredentialSufficient(none)) {
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import android.os.IBinder;
|
|||||||
import android.os.ParcelableException;
|
import android.os.ParcelableException;
|
||||||
import android.os.RemoteCallback;
|
import android.os.RemoteCallback;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
|
import android.os.SystemProperties;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.provider.DeviceConfig;
|
import android.provider.DeviceConfig;
|
||||||
import android.service.resumeonreboot.IResumeOnRebootService;
|
import android.service.resumeonreboot.IResumeOnRebootService;
|
||||||
@@ -55,6 +56,10 @@ public class ResumeOnRebootServiceProvider {
|
|||||||
Manifest.permission.BIND_RESUME_ON_REBOOT_SERVICE;
|
Manifest.permission.BIND_RESUME_ON_REBOOT_SERVICE;
|
||||||
private static final String TAG = "ResumeOnRebootServiceProvider";
|
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 Context mContext;
|
||||||
private final PackageManager mPackageManager;
|
private final PackageManager mPackageManager;
|
||||||
|
|
||||||
@@ -72,12 +77,19 @@ public class ResumeOnRebootServiceProvider {
|
|||||||
private ServiceInfo resolveService() {
|
private ServiceInfo resolveService() {
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.setAction(ResumeOnRebootService.SERVICE_INTERFACE);
|
intent.setAction(ResumeOnRebootService.SERVICE_INTERFACE);
|
||||||
if (PROVIDER_PACKAGE != null && !PROVIDER_PACKAGE.equals("")) {
|
int queryFlag = PackageManager.GET_SERVICES;
|
||||||
intent.setPackage(PROVIDER_PACKAGE);
|
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 =
|
List<ResolveInfo> resolvedIntents = mPackageManager.queryIntentServices(intent, queryFlag);
|
||||||
mPackageManager.queryIntentServices(intent, PackageManager.MATCH_SYSTEM_ONLY);
|
|
||||||
for (ResolveInfo resolvedInfo : resolvedIntents) {
|
for (ResolveInfo resolvedInfo : resolvedIntents) {
|
||||||
if (resolvedInfo.serviceInfo != null
|
if (resolvedInfo.serviceInfo != null
|
||||||
&& PROVIDER_REQUIRED_PERMISSION.equals(resolvedInfo.serviceInfo.permission)) {
|
&& PROVIDER_REQUIRED_PERMISSION.equals(resolvedInfo.serviceInfo.permission)) {
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ import android.content.Context;
|
|||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
import android.os.Process;
|
||||||
import android.os.ResultReceiver;
|
import android.os.ResultReceiver;
|
||||||
import android.os.ShellCallback;
|
import android.os.ShellCallback;
|
||||||
import android.platform.test.annotations.Presubmit;
|
import android.platform.test.annotations.Presubmit;
|
||||||
@@ -86,7 +87,8 @@ public class LockSettingsShellCommandTest {
|
|||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
final Context context = InstrumentationRegistry.getTargetContext();
|
final Context context = InstrumentationRegistry.getTargetContext();
|
||||||
mUserId = ActivityManager.getCurrentUser();
|
mUserId = ActivityManager.getCurrentUser();
|
||||||
mCommand = new LockSettingsShellCommand(mLockPatternUtils);
|
mCommand = new LockSettingsShellCommand(mLockPatternUtils, context, 0,
|
||||||
|
Process.SHELL_UID);
|
||||||
when(mLockPatternUtils.hasSecureLockScreen()).thenReturn(true);
|
when(mLockPatternUtils.hasSecureLockScreen()).thenReturn(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user