diff options
| author | 2021-02-22 21:59:24 +0000 | |
|---|---|---|
| committer | 2021-02-22 21:59:24 +0000 | |
| commit | 49c8eff67cdb309ab89cfe7e667620d16dd38080 (patch) | |
| tree | e0939cb3989e96ba17278906e961f82c49fbf237 | |
| parent | f2e5f5eb1bf4ef6c1688b50686fdb96da25d35b1 (diff) | |
| parent | 4fb94fc9d5b355c34b52f21397512b2fa62effbb (diff) | |
Merge "Adds shell command for CTS" into sc-dev
2 files changed, 70 insertions, 13 deletions
diff --git a/services/core/java/com/android/server/rotationresolver/RotationResolverManagerPerUserService.java b/services/core/java/com/android/server/rotationresolver/RotationResolverManagerPerUserService.java index 6f7c016cb3f6..0cd0458c6b2b 100644 --- a/services/core/java/com/android/server/rotationresolver/RotationResolverManagerPerUserService.java +++ b/services/core/java/com/android/server/rotationresolver/RotationResolverManagerPerUserService.java @@ -65,6 +65,7 @@ final class RotationResolverManagerPerUserService extends @GuardedBy("mLock") RemoteRotationResolverService mRemoteService; + private static String sTestingPackage; private ComponentName mComponentName; RotationResolverManagerPerUserService(@NonNull RotationResolverManagerService main, @@ -136,19 +137,43 @@ 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( diff --git a/services/core/java/com/android/server/rotationresolver/RotationResolverShellCommand.java b/services/core/java/com/android/server/rotationresolver/RotationResolverShellCommand.java index 54a9edba4e03..e5088c023533 100644 --- a/services/core/java/com/android/server/rotationresolver/RotationResolverShellCommand.java +++ b/services/core/java/com/android/server/rotationresolver/RotationResolverShellCommand.java @@ -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."); } } |