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

Commit 454e8dd3 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Implements settings logic for Context Hub AIDL"

parents 2863255d b8815ef9
Loading
Loading
Loading
Loading
+16 −4
Original line number Diff line number Diff line
@@ -137,6 +137,8 @@ public class ContextHubService extends IContextHubService.Stub {

    // True if WiFi is available for the Context Hub
    private boolean mIsWifiAvailable = false;
    private boolean mIsWifiScanningEnabled = false;
    private boolean mIsWifiMainEnabled = false;

    // Lock object for sendWifiSettingUpdate()
    private final Object mSendWifiSettingUpdateLock = new Object();
@@ -1064,10 +1066,20 @@ public class ContextHubService extends IContextHubService.Stub {
    private void sendWifiSettingUpdate(boolean forceUpdate) {
        synchronized (mSendWifiSettingUpdateLock) {
            WifiManager wifiManager = mContext.getSystemService(WifiManager.class);
            boolean enabled = wifiManager.isWifiEnabled() || wifiManager.isScanAlwaysAvailable();
            if (forceUpdate || mIsWifiAvailable != enabled) {
                mIsWifiAvailable = enabled;
                mContextHubWrapper.onWifiSettingChanged(enabled);
            boolean wifiEnabled = wifiManager.isWifiEnabled();
            boolean wifiScanEnabled = wifiManager.isScanAlwaysAvailable();
            boolean wifiAvailable = wifiEnabled || wifiScanEnabled;
            if (forceUpdate || mIsWifiAvailable != wifiAvailable) {
                mIsWifiAvailable = wifiAvailable;
                mContextHubWrapper.onWifiSettingChanged(wifiAvailable);
            }
            if (forceUpdate || mIsWifiScanningEnabled != wifiScanEnabled) {
                mIsWifiScanningEnabled = wifiScanEnabled;
                mContextHubWrapper.onWifiScanningSettingChanged(wifiScanEnabled);
            }
            if (forceUpdate || mIsWifiMainEnabled != wifiEnabled) {
                mIsWifiMainEnabled = wifiEnabled;
                mContextHubWrapper.onWifiMainSettingChanged(wifiEnabled);
            }
        }
    }
+40 −5
Original line number Diff line number Diff line
@@ -197,6 +197,20 @@ public abstract class IContextHubWrapper {
     */
    public abstract void onWifiSettingChanged(boolean enabled);

    /**
     * Notifies the Contexthub implementation of a user WiFi main setting change.
     *
     * @param enabled true if the WiFi main setting has been enabled.
     */
    public abstract void onWifiMainSettingChanged(boolean enabled);

    /**
     * Notifies the Contexthub implementation of a user WiFi scanning setting change.
     *
     * @param enabled true if the WiFi scanning setting has been enabled.
     */
    public abstract void onWifiScanningSettingChanged(boolean enabled);

    /**
     * @return True if this version of the Contexthub HAL supports airplane mode setting
     * notifications.
@@ -335,33 +349,43 @@ public abstract class IContextHubWrapper {
            return new Pair(hubInfoList, new ArrayList<String>(supportedPermissions));
        }

        // TODO(b/194285834): Implement settings logic
        public boolean supportsLocationSettingNotifications() {
            return false;
            return true;
        }

        public boolean supportsWifiSettingNotifications() {
            return false;
            return true;
        }

        public boolean supportsAirplaneModeSettingNotifications() {
            return false;
            return true;
        }

        public boolean supportsMicrophoneDisableSettingNotifications() {
            return false;
            return true;
        }

        public void onLocationSettingChanged(boolean enabled) {
            onSettingChanged(android.hardware.contexthub.Setting.LOCATION, enabled);
        }

        public void onWifiSettingChanged(boolean enabled) {
        }

        public void onAirplaneModeSettingChanged(boolean enabled) {
            onSettingChanged(android.hardware.contexthub.Setting.AIRPLANE_MODE, enabled);
        }

        public void onMicrophoneDisableSettingChanged(boolean enabled) {
            onSettingChanged(android.hardware.contexthub.Setting.MICROPHONE, enabled);
        }

        public void onWifiMainSettingChanged(boolean enabled) {
            onSettingChanged(android.hardware.contexthub.Setting.WIFI_MAIN, enabled);
        }

        public void onWifiScanningSettingChanged(boolean enabled) {
            onSettingChanged(android.hardware.contexthub.Setting.WIFI_SCANNING, enabled);
        }

        @ContextHubTransaction.Result
@@ -414,6 +438,14 @@ public abstract class IContextHubWrapper {
            return success ? ContextHubTransaction.RESULT_SUCCESS
                    : ContextHubTransaction.RESULT_FAILED_UNKNOWN;
        }

        private void onSettingChanged(byte setting, boolean enabled) {
            try {
                mHub.onSettingChanged(setting, enabled);
            } catch (RemoteException e) {
                Log.e(TAG, "RemoteException while sending setting update");
            }
        }
    }

    /**
@@ -531,6 +563,9 @@ public abstract class IContextHubWrapper {
            mCallback = callback;
            mHub.registerCallback(contextHubId, mHidlCallback);
        }

        public void onWifiMainSettingChanged(boolean enabled) {}
        public void onWifiScanningSettingChanged(boolean enabled) {}
    }

    private static class ContextHubWrapperV1_0 extends ContextHubWrapperHidl {