Merge "Adds shell command for CTS" into sc-dev
This commit is contained in:
@@ -65,6 +65,7 @@ final class RotationResolverManagerPerUserService extends
|
||||
@GuardedBy("mLock")
|
||||
RemoteRotationResolverService mRemoteService;
|
||||
|
||||
private static String sTestingPackage;
|
||||
private ComponentName mComponentName;
|
||||
|
||||
RotationResolverManagerPerUserService(@NonNull RotationResolverManagerService main,
|
||||
@@ -135,20 +136,44 @@ final class RotationResolverManagerPerUserService extends
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the testing package name.
|
||||
*
|
||||
* @param packageName the name of the package that implements {@link RotationResolverService}
|
||||
* and is used for testing only.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
void setTestingPackage(String packageName) {
|
||||
sTestingPackage = packageName;
|
||||
mComponentName = resolveRotationResolverService(getContext());
|
||||
}
|
||||
|
||||
/**
|
||||
* get the currently bound component name.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
ComponentName getComponentName() {
|
||||
return mComponentName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides rotation resolver service component name at runtime, making sure it's provided
|
||||
* by the system.
|
||||
*/
|
||||
private static ComponentName resolveRotationResolverService(Context context) {
|
||||
final String serviceConfigPackage = getServiceConfigPackage(context);
|
||||
|
||||
static ComponentName resolveRotationResolverService(Context context) {
|
||||
String resolvedPackage;
|
||||
int flags = PackageManager.MATCH_SYSTEM_ONLY;
|
||||
|
||||
if (!TextUtils.isEmpty(serviceConfigPackage)) {
|
||||
resolvedPackage = serviceConfigPackage;
|
||||
if (!TextUtils.isEmpty(sTestingPackage)) {
|
||||
// Testing Package is set.
|
||||
resolvedPackage = sTestingPackage;
|
||||
flags = PackageManager.GET_META_DATA;
|
||||
} else {
|
||||
return null;
|
||||
final String serviceConfigPackage = getServiceConfigPackage(context);
|
||||
if (!TextUtils.isEmpty(serviceConfigPackage)) {
|
||||
resolvedPackage = serviceConfigPackage;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
final Intent intent = new Intent(
|
||||
@@ -158,14 +183,15 @@ final class RotationResolverManagerPerUserService extends
|
||||
flags, context.getUserId());
|
||||
if (resolveInfo == null || resolveInfo.serviceInfo == null) {
|
||||
Slog.wtf(TAG, String.format("Service %s not found in package %s",
|
||||
RotationResolverService.SERVICE_INTERFACE, serviceConfigPackage
|
||||
));
|
||||
RotationResolverService.SERVICE_INTERFACE, resolvedPackage));
|
||||
return null;
|
||||
}
|
||||
|
||||
final ServiceInfo serviceInfo = resolveInfo.serviceInfo;
|
||||
final String permission = serviceInfo.permission;
|
||||
if (Manifest.permission.BIND_ROTATION_RESOLVER_SERVICE.equals(permission)) {
|
||||
Slog.i(TAG, String.format("Successfully bound the service from package: %s",
|
||||
resolvedPackage));
|
||||
return serviceInfo.getComponentName();
|
||||
}
|
||||
Slog.e(TAG, String.format(
|
||||
|
||||
@@ -16,12 +16,13 @@
|
||||
|
||||
package com.android.server.rotationresolver;
|
||||
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.content.ComponentName;
|
||||
import android.os.CancellationSignal;
|
||||
import android.os.ShellCommand;
|
||||
import android.rotationresolver.RotationResolverInternal.RotationResolverCallbackInternal;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Surface;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
@@ -59,7 +60,7 @@ final class RotationResolverShellCommand extends ShellCommand {
|
||||
}
|
||||
}
|
||||
|
||||
final TestableRotationCallbackInternal mTestableRotationCallbackInternal =
|
||||
static final TestableRotationCallbackInternal sTestableRotationCallbackInternal =
|
||||
new TestableRotationCallbackInternal();
|
||||
|
||||
@Override
|
||||
@@ -73,20 +74,47 @@ final class RotationResolverShellCommand extends ShellCommand {
|
||||
return runResolveRotation();
|
||||
case "get-last-resolution":
|
||||
return getLastResolution();
|
||||
case "set-testing-package":
|
||||
return setTestRotationResolverPackage(getNextArgRequired());
|
||||
case "get-bound-package":
|
||||
return getBoundPackageName();
|
||||
case "clear-testing-package":
|
||||
return resetTestRotationResolverPackage();
|
||||
default:
|
||||
return handleDefaultCommands(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
private int getBoundPackageName() {
|
||||
final PrintWriter out = getOutPrintWriter();
|
||||
final ComponentName componentName = mService.getComponentName();
|
||||
out.println(componentName == null ? "" : componentName.getPackageName());
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int setTestRotationResolverPackage(String testingPackage) {
|
||||
if (!TextUtils.isEmpty((testingPackage))) {
|
||||
mService.setTestingPackage(testingPackage);
|
||||
sTestableRotationCallbackInternal.reset();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int resetTestRotationResolverPackage() {
|
||||
mService.setTestingPackage("");
|
||||
sTestableRotationCallbackInternal.reset();
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int runResolveRotation() {
|
||||
mService.resolveRotationLocked(mTestableRotationCallbackInternal, Surface.ROTATION_0,
|
||||
mService.resolveRotationLocked(sTestableRotationCallbackInternal, Surface.ROTATION_0,
|
||||
Surface.ROTATION_0, "", 2000L, new CancellationSignal());
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int getLastResolution() {
|
||||
final PrintWriter out = getOutPrintWriter();
|
||||
out.println(mTestableRotationCallbackInternal.getLastCallbackCode());
|
||||
out.println(sTestableRotationCallbackInternal.getLastCallbackCode());
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -99,5 +127,8 @@ final class RotationResolverShellCommand extends ShellCommand {
|
||||
pw.println();
|
||||
pw.println(" resolve-rotation: request a rotation resolution.");
|
||||
pw.println(" get-last-resolution: show the last rotation resolution result.");
|
||||
pw.println(" set-testing-package: Set the testing package that implements the service.");
|
||||
pw.println(" get-bound-package: print the bound package that implements the service.");
|
||||
pw.println(" clear-testing-package: reset the testing package.");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user