|
| 1 | +/* |
| 2 | + * SPDX-FileCopyrightText: DerpFest AOSP |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +package com.android.settings.navigationbar; |
| 7 | + |
| 8 | +import android.provider.Settings; |
| 9 | +import android.os.SystemProperties; |
| 10 | +import android.content.Context; |
| 11 | +import android.util.Log; |
| 12 | + |
| 13 | +import androidx.preference.Preference; |
| 14 | +import androidx.preference.SwitchPreferenceCompat; |
| 15 | + |
| 16 | +import com.android.settings.core.BasePreferenceController; |
| 17 | + |
| 18 | +public class KeyboardNoNavigationBarController extends BasePreferenceController implements Preference.OnPreferenceChangeListener { |
| 19 | + |
| 20 | + private static final String KEY_KEYBOARD_NO_NAVIGATION_BAR = "keyboard_no_navigation_bar"; |
| 21 | + private static final String TAG = "NoNavbarController"; |
| 22 | + |
| 23 | + public KeyboardNoNavigationBarController(Context context, String preferenceKey) { |
| 24 | + super(context, preferenceKey); |
| 25 | + } |
| 26 | + |
| 27 | + @Override |
| 28 | + public int getAvailabilityStatus() { |
| 29 | + int navigationMode = Settings.Secure.getInt( |
| 30 | + mContext.getContentResolver(), |
| 31 | + Settings.Secure.NAVIGATION_MODE, |
| 32 | + 0 // Default to 0 if the setting is not found |
| 33 | + ); |
| 34 | + |
| 35 | + return navigationMode == 2 |
| 36 | + ? AVAILABLE |
| 37 | + : UNSUPPORTED_ON_DEVICE; |
| 38 | + |
| 39 | + } |
| 40 | + |
| 41 | + public boolean isChecked() { |
| 42 | + String value = SystemProperties.get("persist.sys.keyboard_no_navigation_bar", "1"); |
| 43 | + boolean result = "1".equals(value); // switch is ON only when overlay is disabled |
| 44 | + Log.d(TAG, "isChecked() reversed logic returning: " + result); |
| 45 | + return result; |
| 46 | + } |
| 47 | + |
| 48 | + @Override |
| 49 | + public boolean onPreferenceChange(Preference preference, Object newValue) { |
| 50 | + if (!(newValue instanceof Boolean)) { |
| 51 | + Log.e(TAG, "Unexpected value type for preference: " + newValue); |
| 52 | + return false; |
| 53 | + } |
| 54 | + |
| 55 | + boolean enabled = (Boolean) newValue; |
| 56 | + String newPropValue = enabled ? "1" : "0"; |
| 57 | + SystemProperties.set("persist.sys.keyboard_no_navigation_bar", newPropValue); |
| 58 | + Log.d(TAG, "onPreferenceChange() set persist.sys.keyboard_no_navigation_bar to: " + newPropValue); |
| 59 | + |
| 60 | + String command = enabled |
| 61 | + ? "cmd overlay disable com.voltage.overlay.customization.keyboard.nonavbar" |
| 62 | + : "cmd overlay enable com.voltage.overlay.customization.keyboard.nonavbar"; |
| 63 | + |
| 64 | + try { |
| 65 | + Runtime.getRuntime().exec(new String[]{"sh", "-c", command}); |
| 66 | + Log.d(TAG, "Executed command: " + command); |
| 67 | + } catch (Exception e) { |
| 68 | + Log.e(TAG, "Failed to execute overlay command", e); |
| 69 | + } |
| 70 | + |
| 71 | + return true; |
| 72 | + } |
| 73 | + |
| 74 | + @Override |
| 75 | + public void updateState(Preference preference) { |
| 76 | + if (preference instanceof SwitchPreferenceCompat) { |
| 77 | + boolean checked = isChecked(); |
| 78 | + ((SwitchPreferenceCompat) preference).setChecked(checked); |
| 79 | + Log.d(TAG, "updateState() setting switch to: " + checked); |
| 80 | + } |
| 81 | + } |
| 82 | +} |
0 commit comments