Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 00058175 authored by Matthew Sedam's avatar Matthew Sedam
Browse files

Add setTestMode to the Context Hub Service

Bug: 258074235
Test: m, flash, boot, logs normal
Test: manual test
Change-Id: I905f718730513dbca5f2fca3c861380fea38fcc7
parent c6346aa1
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -113,4 +113,8 @@ interface IContextHubService {
    // Queries for a list of preloaded nanoapps
    @EnforcePermission("ACCESS_CONTEXT_HUB")
    long[] getPreloadedNanoAppIds(in ContextHubInfo hubInfo);

    // Enables or disables test mode
    @EnforcePermission("ACCESS_CONTEXT_HUB")
    boolean setTestMode(in boolean enable);
}
+28 −0
Original line number Diff line number Diff line
@@ -1155,6 +1155,34 @@ public class ContextHubService extends IContextHubService.Stub {
        return nanoappIds;
    }

    @android.annotation.EnforcePermission(android.Manifest.permission.ACCESS_CONTEXT_HUB)
    /**
     * Puts the context hub in and out of test mode. Test mode is a clean state
     * where tests can be executed in the same environment. If enable is true,
     * this will enable test mode by unloading all nanoapps. If enable is false,
     * this will disable test mode and reverse the actions of enabling test mode
     * by loading all preloaded nanoapps. This puts CHRE in a normal state.
     *
     * This should only be used for a test environment, either through a
     * @TestApi or development tools. This should not be used in a production
     * environment.
     *
     * @param enable If true, put the context hub in test mode. If false, disable
     *               test mode.
     * @return       If true, the operation was successful; false otherwise.
     */
    @Override
    public boolean setTestMode(boolean enable) {
        super.setTestMode_enforcePermission();
        boolean status = mContextHubWrapper.setTestMode(enable);

        // Query nanoapps to update service state after test mode state change.
        for (int contextHubId: mDefaultClientMap.keySet()) {
            queryNanoAppsInternal(contextHubId);
        }
        return status;
    }

    @Override
    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
+37 −0
Original line number Diff line number Diff line
@@ -382,6 +382,23 @@ public abstract class IContextHubWrapper {
     */
    public abstract void registerExistingCallback(int contextHubId) throws RemoteException;

    /**
     * Puts the context hub in and out of test mode. Test mode is a clean state
     * where tests can be executed in the same environment. If enable is true,
     * this will enable test mode by unloading all nanoapps. If enable is false,
     * this will disable test mode and reverse the actions of enabling test mode
     * by loading all preloaded nanoapps. This puts CHRE in a normal state.
     *
     * This should only be used for a test environment, either through a
     * @TestApi or development tools. This should not be used in a production
     * environment.
     *
     * @param enable If true, put the context hub in test mode. If false, disable
     *               test mode.
     * @return       If true, the operation was successful; false otherwise.
     */
    public abstract boolean setTestMode(boolean enable);

    private static class ContextHubWrapperAidl extends IContextHubWrapper
            implements IBinder.DeathRecipient {
        private android.hardware.contexthub.IContextHub mHub;
@@ -741,6 +758,22 @@ public abstract class IContextHubWrapper {
            registerExistingCallback(contextHubId);
        }

        public boolean setTestMode(boolean enable) {
            android.hardware.contexthub.IContextHub hub = getHub();
            if (hub == null) {
                return false;
            }

            try {
                hub.setTestMode(enable);
                return true;
            } catch (RemoteException | ServiceSpecificException e) {
                Log.e(TAG, "Exception while setting test mode (enable: "
                        + (enable ? "true" : "false") + "): " + e.getMessage());
                return false;
            }
        }

        private void onSettingChanged(byte setting, boolean enabled) {
            android.hardware.contexthub.IContextHub hub = getHub();
            if (hub == null) {
@@ -911,6 +944,10 @@ public abstract class IContextHubWrapper {
            mHub.registerCallback(contextHubId, callback);
        }

        public boolean setTestMode(boolean enable) {
            return false;
        }

        public boolean supportsBtSettingNotifications() {
            return false;
        }