diff --git a/core/api/test-current.txt b/core/api/test-current.txt index 94075e58b01d7..d58674c3d4b19 100644 --- a/core/api/test-current.txt +++ b/core/api/test-current.txt @@ -1414,6 +1414,8 @@ package android.hardware.lights { package android.hardware.location { public final class ContextHubManager { + method @NonNull @RequiresPermission(android.Manifest.permission.ACCESS_CONTEXT_HUB) public boolean disableTestMode(); + method @NonNull @RequiresPermission(android.Manifest.permission.ACCESS_CONTEXT_HUB) public boolean enableTestMode(); method @NonNull @RequiresPermission(android.Manifest.permission.ACCESS_CONTEXT_HUB) public long[] getPreloadedNanoAppIds(@NonNull android.hardware.location.ContextHubInfo); } diff --git a/core/java/android/hardware/location/ContextHubManager.java b/core/java/android/hardware/location/ContextHubManager.java index ac23af4396de0..01ce7b9c0731d 100644 --- a/core/java/android/hardware/location/ContextHubManager.java +++ b/core/java/android/hardware/location/ContextHubManager.java @@ -994,6 +994,51 @@ public final class ContextHubManager { return nanoappIds; } + /** + * Puts the Context Hub in test mode. + * + * The purpose of this API is to make testing CHRE/Context Hub more + * predictable and robust. This temporarily unloads all + * nanoapps. + * + * Note that this API must not cause CHRE/Context Hub to behave differently + * in test compared to production. + * + * @return true if the enable test mode operation succeeded. + * @hide + */ + @TestApi + @RequiresPermission(android.Manifest.permission.ACCESS_CONTEXT_HUB) + @NonNull public boolean enableTestMode() { + try { + return mService.setTestMode(true); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + + /** + * Puts the Context Hub out of test mode. + * + * This API will undo any previously made enableTestMode() calls. + * After this API is called, it should restore the state of the system + * to the normal/production mode before any enableTestMode() call was + * made. If the enableTestMode() call unloaded any nanoapps + * to enter test mode, it should reload those nanoapps in this API call. + * + * @return true if the disable operation succeeded. + * @hide + */ + @TestApi + @RequiresPermission(android.Manifest.permission.ACCESS_CONTEXT_HUB) + @NonNull public boolean disableTestMode() { + try { + return mService.setTestMode(false); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + /** * Unregister a callback for receive messages from the context hub. *