Loading services/contentcapture/java/com/android/server/contentcapture/ContentCaptureManagerServiceShellCommand.java +27 −0 Original line number Diff line number Diff line Loading @@ -77,6 +77,15 @@ public final class ContentCaptureManagerServiceShellCommand extends ShellCommand pw.println(" Temporarily (for DURATION ms) changes the service implemtation."); pw.println(" To reset, call with just the USER_ID argument."); pw.println(""); pw.println(""); pw.println(" set default-service-enabled USER_ID [true|false]"); pw.println(" Enable / disable the default service for the user."); pw.println(""); pw.println(""); pw.println(" get default-service-enabled USER_ID"); pw.println(" Checks whether the default service is enabled for the user."); pw.println(""); pw.println(""); pw.println(" list sessions [--user USER_ID]"); pw.println(" Lists all pending sessions."); pw.println(""); Loading @@ -91,6 +100,8 @@ public final class ContentCaptureManagerServiceShellCommand extends ShellCommand switch(what) { case "bind-instant-service-allowed": return getBindInstantService(pw); case "default-service-enabled": return getDefaultServiceEnabled(pw); default: pw.println("Invalid set: " + what); return -1; Loading @@ -105,6 +116,8 @@ public final class ContentCaptureManagerServiceShellCommand extends ShellCommand return setBindInstantService(pw); case "temporary-service": return setTemporaryService(pw); case "default-service-enabled": return setDefaultServiceEnabled(); default: pw.println("Invalid set: " + what); return -1; Loading Loading @@ -149,6 +162,20 @@ public final class ContentCaptureManagerServiceShellCommand extends ShellCommand return 0; } private int setDefaultServiceEnabled() { final int userId = getNextIntArgRequired(); final boolean enabled = Boolean.parseBoolean(getNextArg()); mService.setDefaultServiceEnabled(userId, enabled); return 0; } private int getDefaultServiceEnabled(PrintWriter pw) { final int userId = getNextIntArgRequired(); final boolean enabled = mService.isDefaultServiceEnabled(userId); pw.println(enabled); return 0; } private int requestDestroy(PrintWriter pw) { if (!isNextArgSessions(pw)) { return -1; Loading services/core/java/com/android/server/infra/AbstractMasterSystemService.java +40 −0 Original line number Diff line number Diff line Loading @@ -285,6 +285,46 @@ public abstract class AbstractMasterSystemService<M extends AbstractMasterSystem } } /** * Sets whether the default service should be used. * * <p>Typically used during CTS tests to make sure only the default service doesn't interfere * with the test results. * * @throws SecurityException if caller is not allowed to manage this service's settings. */ public final void setDefaultServiceEnabled(@UserIdInt int userId, boolean enabled) { Slog.i(mTag, "setDefaultServiceEnabled() for userId " + userId + ": " + enabled); enforceCallingPermissionForManagement(); synchronized (mLock) { final S oldService = peekServiceForUserLocked(userId); if (oldService != null) { oldService.removeSelfFromCacheLocked(); } mServiceNameResolver.setDefaultServiceEnabled(userId, enabled); // Must update the service on cache so its initialization code is triggered updateCachedServiceLocked(userId); } } /** * Checks whether the default service should be used. * * <p>Typically used during CTS tests to make sure only the default service doesn't interfere * with the test results. * * @throws SecurityException if caller is not allowed to manage this service's settings. */ public final boolean isDefaultServiceEnabled(@UserIdInt int userId) { enforceCallingPermissionForManagement(); synchronized (mLock) { return mServiceNameResolver.isDefaultServiceEnabled(userId); } } /** * Gets the maximum time the service implementation can be changed. * Loading services/core/java/com/android/server/infra/FrameworkResourcesServiceNameResolver.java +41 −4 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import android.os.SystemClock; import android.text.TextUtils; import android.util.Slog; import android.util.SparseArray; import android.util.SparseBooleanArray; import android.util.TimeUtils; import com.android.internal.annotations.GuardedBy; Loading Loading @@ -60,6 +61,15 @@ public final class FrameworkResourcesServiceNameResolver implements ServiceNameR @GuardedBy("mLock") private final SparseArray<String> mTemporaryServiceNames = new SparseArray<>(); /** * Map of default services that have been disabled by * {@link #setDefaultServiceEnabled(int, boolean)},keyed by {@code userId}. * * <p>Typically used by Shell command and/or CTS tests. */ @GuardedBy("mLock") private final SparseBooleanArray mDefaultServicesDisabled = new SparseBooleanArray(); /** * When the temporary service will expire (and reset back to the default). */ Loading Loading @@ -99,12 +109,18 @@ public final class FrameworkResourcesServiceNameResolver implements ServiceNameR final String temporaryName = mTemporaryServiceNames.get(userId); if (temporaryName != null) { // Always log it, as it should only be used on CTS or during development Slog.w(TAG, "getComponentName(): using temporary name " + temporaryName Slog.w(TAG, "getServiceName(): using temporary name " + temporaryName + " for user " + userId); return temporaryName; } else { return getDefaultServiceName(userId); } final boolean disabled = mDefaultServicesDisabled.get(userId); if (disabled) { // Always log it, as it should only be used on CTS or during development Slog.w(TAG, "getServiceName(): temporary name not set and default disabled for " + "user " + userId); return null; } return getDefaultServiceName(userId); } } Loading Loading @@ -157,6 +173,24 @@ public final class FrameworkResourcesServiceNameResolver implements ServiceNameR } } @Override public void setDefaultServiceEnabled(int userId, boolean enabled) { synchronized (mLock) { if (enabled) { mDefaultServicesDisabled.removeAt(userId); } else { mDefaultServicesDisabled.put(userId, true); } } } @Override public boolean isDefaultServiceEnabled(int userId) { synchronized (mLock) { return mDefaultServicesDisabled.get(userId); } } @Override public String toString() { return "FrameworkResourcesServiceNamer[temps=" + mTemporaryServiceNames + "]"; Loading @@ -168,6 +202,7 @@ public final class FrameworkResourcesServiceNameResolver implements ServiceNameR synchronized (mLock) { pw.print("FrameworkResourcesServiceNamer: resId="); pw.print(mResourceId); pw.print(", numberTemps="); pw.print(mTemporaryServiceNames.size()); pw.print(", enabledDefaults="); pw.print(mDefaultServicesDisabled.size()); } } Loading @@ -181,7 +216,9 @@ public final class FrameworkResourcesServiceNameResolver implements ServiceNameR final long ttl = mTemporaryServiceExpiration - SystemClock.elapsedRealtime(); pw.print(" (expires in "); TimeUtils.formatDuration(ttl, pw); pw.print("), "); } pw.print("defaultName="); pw.println(getDefaultServiceName(userId)); pw.print("defaultName="); pw.print(getDefaultServiceName(userId)); final boolean disabled = mDefaultServicesDisabled.get(userId); pw.println(disabled ? " (disabled)" : " (enabled)"); } } Loading services/core/java/com/android/server/infra/ServiceNameResolver.java +30 −0 Original line number Diff line number Diff line Loading @@ -107,6 +107,36 @@ public interface ServiceNameResolver { throw new UnsupportedOperationException("temporary user not supported"); } /** * Sets whether the default service should be used when the temporary service is not set. * * <p>Typically used during CTS tests to make sure only the default service doesn't interfere * with the test results. * * @param userId user handle * @param enabled whether the default service should be used when the temporary service is not * set * * @throws UnsupportedOperationException if not implemented. */ default void setDefaultServiceEnabled(@UserIdInt int userId, boolean enabled) { throw new UnsupportedOperationException("changing default service not supported"); } /** * Checks whether the default service should be used when the temporary service is not set. * * <p>Typically used during CTS tests to make sure only the default service doesn't interfere * with the test results. * * @param userId user handle * * @throws UnsupportedOperationException if not implemented. */ default boolean isDefaultServiceEnabled(@UserIdInt int userId) { throw new UnsupportedOperationException("checking default service not supported"); } /** * Dumps the generic info in just one line (without calling {@code println}. */ Loading Loading
services/contentcapture/java/com/android/server/contentcapture/ContentCaptureManagerServiceShellCommand.java +27 −0 Original line number Diff line number Diff line Loading @@ -77,6 +77,15 @@ public final class ContentCaptureManagerServiceShellCommand extends ShellCommand pw.println(" Temporarily (for DURATION ms) changes the service implemtation."); pw.println(" To reset, call with just the USER_ID argument."); pw.println(""); pw.println(""); pw.println(" set default-service-enabled USER_ID [true|false]"); pw.println(" Enable / disable the default service for the user."); pw.println(""); pw.println(""); pw.println(" get default-service-enabled USER_ID"); pw.println(" Checks whether the default service is enabled for the user."); pw.println(""); pw.println(""); pw.println(" list sessions [--user USER_ID]"); pw.println(" Lists all pending sessions."); pw.println(""); Loading @@ -91,6 +100,8 @@ public final class ContentCaptureManagerServiceShellCommand extends ShellCommand switch(what) { case "bind-instant-service-allowed": return getBindInstantService(pw); case "default-service-enabled": return getDefaultServiceEnabled(pw); default: pw.println("Invalid set: " + what); return -1; Loading @@ -105,6 +116,8 @@ public final class ContentCaptureManagerServiceShellCommand extends ShellCommand return setBindInstantService(pw); case "temporary-service": return setTemporaryService(pw); case "default-service-enabled": return setDefaultServiceEnabled(); default: pw.println("Invalid set: " + what); return -1; Loading Loading @@ -149,6 +162,20 @@ public final class ContentCaptureManagerServiceShellCommand extends ShellCommand return 0; } private int setDefaultServiceEnabled() { final int userId = getNextIntArgRequired(); final boolean enabled = Boolean.parseBoolean(getNextArg()); mService.setDefaultServiceEnabled(userId, enabled); return 0; } private int getDefaultServiceEnabled(PrintWriter pw) { final int userId = getNextIntArgRequired(); final boolean enabled = mService.isDefaultServiceEnabled(userId); pw.println(enabled); return 0; } private int requestDestroy(PrintWriter pw) { if (!isNextArgSessions(pw)) { return -1; Loading
services/core/java/com/android/server/infra/AbstractMasterSystemService.java +40 −0 Original line number Diff line number Diff line Loading @@ -285,6 +285,46 @@ public abstract class AbstractMasterSystemService<M extends AbstractMasterSystem } } /** * Sets whether the default service should be used. * * <p>Typically used during CTS tests to make sure only the default service doesn't interfere * with the test results. * * @throws SecurityException if caller is not allowed to manage this service's settings. */ public final void setDefaultServiceEnabled(@UserIdInt int userId, boolean enabled) { Slog.i(mTag, "setDefaultServiceEnabled() for userId " + userId + ": " + enabled); enforceCallingPermissionForManagement(); synchronized (mLock) { final S oldService = peekServiceForUserLocked(userId); if (oldService != null) { oldService.removeSelfFromCacheLocked(); } mServiceNameResolver.setDefaultServiceEnabled(userId, enabled); // Must update the service on cache so its initialization code is triggered updateCachedServiceLocked(userId); } } /** * Checks whether the default service should be used. * * <p>Typically used during CTS tests to make sure only the default service doesn't interfere * with the test results. * * @throws SecurityException if caller is not allowed to manage this service's settings. */ public final boolean isDefaultServiceEnabled(@UserIdInt int userId) { enforceCallingPermissionForManagement(); synchronized (mLock) { return mServiceNameResolver.isDefaultServiceEnabled(userId); } } /** * Gets the maximum time the service implementation can be changed. * Loading
services/core/java/com/android/server/infra/FrameworkResourcesServiceNameResolver.java +41 −4 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import android.os.SystemClock; import android.text.TextUtils; import android.util.Slog; import android.util.SparseArray; import android.util.SparseBooleanArray; import android.util.TimeUtils; import com.android.internal.annotations.GuardedBy; Loading Loading @@ -60,6 +61,15 @@ public final class FrameworkResourcesServiceNameResolver implements ServiceNameR @GuardedBy("mLock") private final SparseArray<String> mTemporaryServiceNames = new SparseArray<>(); /** * Map of default services that have been disabled by * {@link #setDefaultServiceEnabled(int, boolean)},keyed by {@code userId}. * * <p>Typically used by Shell command and/or CTS tests. */ @GuardedBy("mLock") private final SparseBooleanArray mDefaultServicesDisabled = new SparseBooleanArray(); /** * When the temporary service will expire (and reset back to the default). */ Loading Loading @@ -99,12 +109,18 @@ public final class FrameworkResourcesServiceNameResolver implements ServiceNameR final String temporaryName = mTemporaryServiceNames.get(userId); if (temporaryName != null) { // Always log it, as it should only be used on CTS or during development Slog.w(TAG, "getComponentName(): using temporary name " + temporaryName Slog.w(TAG, "getServiceName(): using temporary name " + temporaryName + " for user " + userId); return temporaryName; } else { return getDefaultServiceName(userId); } final boolean disabled = mDefaultServicesDisabled.get(userId); if (disabled) { // Always log it, as it should only be used on CTS or during development Slog.w(TAG, "getServiceName(): temporary name not set and default disabled for " + "user " + userId); return null; } return getDefaultServiceName(userId); } } Loading Loading @@ -157,6 +173,24 @@ public final class FrameworkResourcesServiceNameResolver implements ServiceNameR } } @Override public void setDefaultServiceEnabled(int userId, boolean enabled) { synchronized (mLock) { if (enabled) { mDefaultServicesDisabled.removeAt(userId); } else { mDefaultServicesDisabled.put(userId, true); } } } @Override public boolean isDefaultServiceEnabled(int userId) { synchronized (mLock) { return mDefaultServicesDisabled.get(userId); } } @Override public String toString() { return "FrameworkResourcesServiceNamer[temps=" + mTemporaryServiceNames + "]"; Loading @@ -168,6 +202,7 @@ public final class FrameworkResourcesServiceNameResolver implements ServiceNameR synchronized (mLock) { pw.print("FrameworkResourcesServiceNamer: resId="); pw.print(mResourceId); pw.print(", numberTemps="); pw.print(mTemporaryServiceNames.size()); pw.print(", enabledDefaults="); pw.print(mDefaultServicesDisabled.size()); } } Loading @@ -181,7 +216,9 @@ public final class FrameworkResourcesServiceNameResolver implements ServiceNameR final long ttl = mTemporaryServiceExpiration - SystemClock.elapsedRealtime(); pw.print(" (expires in "); TimeUtils.formatDuration(ttl, pw); pw.print("), "); } pw.print("defaultName="); pw.println(getDefaultServiceName(userId)); pw.print("defaultName="); pw.print(getDefaultServiceName(userId)); final boolean disabled = mDefaultServicesDisabled.get(userId); pw.println(disabled ? " (disabled)" : " (enabled)"); } } Loading
services/core/java/com/android/server/infra/ServiceNameResolver.java +30 −0 Original line number Diff line number Diff line Loading @@ -107,6 +107,36 @@ public interface ServiceNameResolver { throw new UnsupportedOperationException("temporary user not supported"); } /** * Sets whether the default service should be used when the temporary service is not set. * * <p>Typically used during CTS tests to make sure only the default service doesn't interfere * with the test results. * * @param userId user handle * @param enabled whether the default service should be used when the temporary service is not * set * * @throws UnsupportedOperationException if not implemented. */ default void setDefaultServiceEnabled(@UserIdInt int userId, boolean enabled) { throw new UnsupportedOperationException("changing default service not supported"); } /** * Checks whether the default service should be used when the temporary service is not set. * * <p>Typically used during CTS tests to make sure only the default service doesn't interfere * with the test results. * * @param userId user handle * * @throws UnsupportedOperationException if not implemented. */ default boolean isDefaultServiceEnabled(@UserIdInt int userId) { throw new UnsupportedOperationException("checking default service not supported"); } /** * Dumps the generic info in just one line (without calling {@code println}. */ Loading