summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Yi Jiang <eejiang@google.com> 2021-05-10 23:30:48 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2021-05-10 23:30:48 +0000
commit1e577bb281ff5a27ff8bf5beaabb2b8679d6d084 (patch)
tree1b7344648a09438358b3e54ba449867b99754314
parent8a67239a679a0da1850a6dec8e4c38dcf70345c4 (diff)
parentcb800aa3990eb5a6ad4844a38ec00f65eecdea04 (diff)
Merge "Simplifies the service resolving logic in RRMS" into sc-dev
-rw-r--r--services/core/java/com/android/server/rotationresolver/RotationResolverManagerPerUserService.java92
-rw-r--r--services/core/java/com/android/server/rotationresolver/RotationResolverShellCommand.java31
2 files changed, 41 insertions, 82 deletions
diff --git a/services/core/java/com/android/server/rotationresolver/RotationResolverManagerPerUserService.java b/services/core/java/com/android/server/rotationresolver/RotationResolverManagerPerUserService.java
index 1dbe3e485938..81bf29b19604 100644
--- a/services/core/java/com/android/server/rotationresolver/RotationResolverManagerPerUserService.java
+++ b/services/core/java/com/android/server/rotationresolver/RotationResolverManagerPerUserService.java
@@ -19,24 +19,20 @@ package com.android.server.rotationresolver;
import static android.service.rotationresolver.RotationResolverService.ROTATION_RESULT_FAILURE_CANCELLED;
import static com.android.server.rotationresolver.RotationResolverManagerService.RESOLUTION_UNAVAILABLE;
-import static com.android.server.rotationresolver.RotationResolverManagerService.getServiceConfigPackage;
import static com.android.server.rotationresolver.RotationResolverManagerService.logRotationStats;
import android.Manifest;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
+import android.app.AppGlobals;
import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.os.CancellationSignal;
+import android.os.RemoteException;
import android.rotationresolver.RotationResolverInternal;
import android.service.rotationresolver.RotationResolutionRequest;
-import android.service.rotationresolver.RotationResolverService;
-import android.text.TextUtils;
import android.util.IndentingPrintWriter;
import android.util.Slog;
@@ -65,7 +61,6 @@ final class RotationResolverManagerPerUserService extends
@GuardedBy("mLock")
RemoteRotationResolverService mRemoteService;
- private static String sTestingPackage;
private ComponentName mComponentName;
RotationResolverManagerPerUserService(@NonNull RotationResolverManagerService main,
@@ -139,18 +134,6 @@ 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
@@ -158,63 +141,40 @@ final class RotationResolverManagerPerUserService extends
return mComponentName;
}
- /**
- * Provides rotation resolver service component name at runtime, making sure it's provided
- * by the system.
- */
- static ComponentName resolveRotationResolverService(Context context) {
- String resolvedPackage;
- int flags = PackageManager.MATCH_SYSTEM_ONLY;
- if (!TextUtils.isEmpty(sTestingPackage)) {
- // Testing Package is set.
- resolvedPackage = sTestingPackage;
- flags = PackageManager.GET_META_DATA;
- } else {
- final String serviceConfigPackage = getServiceConfigPackage(context);
- if (!TextUtils.isEmpty(serviceConfigPackage)) {
- resolvedPackage = serviceConfigPackage;
- } else {
- return null;
- }
- }
-
- final Intent intent = new Intent(
- RotationResolverService.SERVICE_INTERFACE).setPackage(resolvedPackage);
-
- final ResolveInfo resolveInfo = context.getPackageManager().resolveServiceAsUser(intent,
- flags, context.getUserId());
- if (resolveInfo == null || resolveInfo.serviceInfo == null) {
- Slog.wtf(TAG, String.format("Service %s not found in package %s",
- 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(
- "Service %s should require %s permission. Found %s permission",
- serviceInfo.getComponentName(),
- Manifest.permission.BIND_ROTATION_RESOLVER_SERVICE,
- serviceInfo.permission));
- return null;
- }
-
/** Resolves and sets up the rotation resolver service if it had not been done yet. */
@GuardedBy("mLock")
@VisibleForTesting
boolean isServiceAvailableLocked() {
if (mComponentName == null) {
- mComponentName = resolveRotationResolverService(getContext());
+ mComponentName = updateServiceInfoLocked();
}
return mComponentName != null;
}
+ @Override // from PerUserSystemService
+ protected ServiceInfo newServiceInfoLocked(@NonNull ComponentName serviceComponent)
+ throws PackageManager.NameNotFoundException {
+ ServiceInfo serviceInfo;
+ try {
+ serviceInfo = AppGlobals.getPackageManager().getServiceInfo(serviceComponent,
+ PackageManager.GET_META_DATA, mUserId);
+ if (serviceInfo != null) {
+ final String permission = serviceInfo.permission;
+ if (!Manifest.permission.BIND_ROTATION_RESOLVER_SERVICE.equals(permission)) {
+ throw new SecurityException(String.format(
+ "Service %s requires %s permission. Found %s permission",
+ serviceInfo.getComponentName(),
+ Manifest.permission.BIND_ROTATION_RESOLVER_SERVICE,
+ serviceInfo.permission));
+ }
+ }
+ } catch (RemoteException e) {
+ throw new PackageManager.NameNotFoundException(
+ "Could not get service for " + serviceComponent);
+ }
+ return serviceInfo;
+ }
@GuardedBy("mLock")
private void cancelLocked() {
diff --git a/services/core/java/com/android/server/rotationresolver/RotationResolverShellCommand.java b/services/core/java/com/android/server/rotationresolver/RotationResolverShellCommand.java
index a0e04ee7a20d..9f3f0968028f 100644
--- a/services/core/java/com/android/server/rotationresolver/RotationResolverShellCommand.java
+++ b/services/core/java/com/android/server/rotationresolver/RotationResolverShellCommand.java
@@ -23,7 +23,6 @@ import android.os.CancellationSignal;
import android.os.ShellCommand;
import android.rotationresolver.RotationResolverInternal.RotationResolverCallbackInternal;
import android.service.rotationresolver.RotationResolutionRequest;
-import android.text.TextUtils;
import android.view.Surface;
import java.io.PrintWriter;
@@ -75,12 +74,10 @@ 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();
+ case "set-temporary-service":
+ return setTemporaryService(getNextArgRequired());
default:
return handleDefaultCommands(cmd);
}
@@ -93,17 +90,18 @@ final class RotationResolverShellCommand extends ShellCommand {
return 0;
}
- private int setTestRotationResolverPackage(String testingPackage) {
- if (!TextUtils.isEmpty((testingPackage))) {
- mService.setTestingPackage(testingPackage);
- sTestableRotationCallbackInternal.reset();
+ private int setTemporaryService(String serviceName) {
+ final PrintWriter out = getOutPrintWriter();
+ if (serviceName == null) {
+ mService.getMaster().resetTemporaryService(mService.getUserId());
+ out.println("RotationResolverService temporary reset. ");
+ return 0;
}
- return 0;
- }
- private int resetTestRotationResolverPackage() {
- mService.setTestingPackage("");
- sTestableRotationCallbackInternal.reset();
+ final int duration = Integer.parseInt(getNextArgRequired());
+ mService.getMaster().setTemporaryService(mService.getUserId(), serviceName, duration);
+ out.println("RotationResolverService temporarily set to " + serviceName
+ + " for " + duration + "ms");
return 0;
}
@@ -130,8 +128,9 @@ 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.");
+ pw.println(" set-temporary-service [COMPONENT_NAME DURATION]");
+ pw.println(" Temporarily (for DURATION ms) changes the service implementation.");
+ pw.println(" To reset, call with no argument.");
}
}