diff options
author | Davide Garberi <dade.garberi@gmail.com> | 2019-05-10 19:33:58 +0200 |
---|---|---|
committer | Davide Garberi <dade.garberi@gmail.com> | 2019-05-10 22:15:52 +0200 |
commit | 08ea0bdd18cf066aae40859a01e7b21a0f36ef87 (patch) | |
tree | e694ebb8595538b68f8b08f3a3617a779d2fd082 /configpanel | |
parent | 1ec6d6b8ee8d6a3ab7a785f7b9023f0e1c1746f3 (diff) |
msm8996-common: Import configpanel
Squash of the following:
commit b5d41936b2519b2404b44bc3ce5bd51555732e30
Author: Bruno Martins <bgcngm@gmail.com>
Date: Tue Jan 15 00:36:22 2019 +0000
msm8996-common: ConfigPanel: Abandon LineageHardwareManager usage
Change-Id: I5f0d01222eecbde14887b0298811bdceab65db57
commit 4338acf9a848acbac4a60432e891747d23ba2977
Author: Anton Hansson <hansson@google.com>
Date: Wed Feb 21 14:11:44 2018 +0000
msm8996-common: Set LOCAL_SDK_VERSION where possible.
This change sets LOCAL_SDK_VERSION for all packages where
this is possible without breaking the build, and
LOCAL_PRIVATE_PLATFORM_APIS := true otherwise.
Setting one of these two will be made required soon, and this
is a change in preparation for that. Not setting LOCAL_SDK_VERSION
makes the app implicitly depend on the bootclasspath, which is
often not required. This change effectively makes depending on
private apis opt-in rather than opt-out.
Test: make relevant packages
Bug: 73535841
Change-Id: Ic906adbd670c4dbfe2cdf0b71cdbeaf9ac08a27e
commit 4c96c168c686c13f1d20a304c9242f2f01b8a103
Author: Giuseppe Barillari <joe2k01dev@gmail.com>
Date: Sun May 27 21:25:24 2018 +0200
msm8996-common: configpanel: Define LOCAL_PRIVILEGED_MODULE only once
Change-Id: I256dd33a1bc69b8295ddcc15db9ccd29167c96dc
Signed-off-by: Giuseppe Barillari <joe2k01dev@gmail.com>
commit 393fa378f8ebda5d20798e9cec6d86968251c0de
Author: Bruno Martins <bgcngm@gmail.com>
Date: Thu May 24 15:33:19 2018 +0100
msm8996-common: ConfigPanel: Define non-indexable keys
* This ensures that keys related with unsupported features
are hidden from search results.
Change-Id: I2220ff21aee5d8015bea4073073492f4560e3703
commit 0f67e39f803c0c13cca85901760f8f467e18ceed
Author: Giuseppe Barillari <joe2k01dev@gmail.com>
Date: Sat Feb 24 20:39:11 2018 +0100
msm8996-common: ConfigPanel: Handle cyttsp reversed keys proc entry
* This adds support for button swap feature on Mi Note 2
Change-Id: I82bfa3ed6ed64891cba84d16c07748930cee6272
Signed-off-by: Giuseppe Barillari <joe2k01dev@gmail.com>
commit d56cfb06245a9af9f87143e50ec9bf563ad7b468
Author: Asher Simonds <dayanhammer@gmail.com>
Date: Wed Feb 14 00:20:29 2018 +0200
msm8996-common: ConfigPanel: Add adaptive icon
Change-Id: I8009c1dd93cc9c6c6d66db550a79a8781a4254b0
commit 1ca4c23c97cf88277e814f2a510892e08313f090
Author: Bruno Martins <bgcngm@gmail.com>
Date: Tue Feb 13 23:18:08 2018 +0000
msm8996-common: ConfigPanel: Bump SDK version
Change-Id: I57d60c73228f47a5267a9536ed058f6053e6ed13
commit 29f2e9cf3b43f7fcb0d4a64179b6f20661ea5491
Author: Bruno Martins <bgcngm@gmail.com>
Date: Thu Oct 5 23:33:44 2017 +0100
msm8996-common: ConfigPanel: Restore back button to the action bar
* This restores the relevant code that was removed in commit c243b72bf0e5bd460167b7bb7d2f4286a5e4eea8
Change-Id: I69afd5f8ef4c59f215a201bd76acc3b2015c0a73
commit c130e2f56860a7ab2d0472694c61f8248c2aab2e
Author: Bruno Martins <bgcngm@gmail.com>
Date: Thu Oct 5 23:15:51 2017 +0100
msm8996-common: ConfigPanel: Build with AAPT2
Change-Id: I0713c2ffd35c768ca863dc36778dbfe0892240f5
commit cf4e4a9554618d2b6b56a1584f78bd03c01c3b36
Author: Bruno Martins <bgcngm@gmail.com>
Date: Thu Oct 5 23:08:09 2017 +0100
msm8996-common: ConfigPanel: Re-integrate into Settings
* Apply the default Oreo theme and inherit the layouts from Google
for the Settings app, in order to keep UI consistency.
* Get rid of SettingsDrawerActivity as it no longer fits in.
* Add required appcompat and preference support libraries.
* Integrate into our custom Button settings category by defining the
expected action.
Change-Id: Ic2e9768552751a59e49ec00576b202e8223268e7
commit 5be570c80cb12fca9255a094b52e75b79f5a8bb9
Author: Paul Keith <javelinanddart@gmail.com>
Date: Thu Nov 23 22:14:40 2017 +0100
msm8996-common: ConfigPanel: Update KeyHandler for API change
Change-Id: I047e903572d09109b49b554acd5eeecc503d37d1
commit 11a871461baf9a51a7cbdecd47a4f3bea4a47660
Author: Bruno Martins <bgcngm@gmail.com>
Date: Thu Oct 5 00:33:30 2017 +0100
msm8996-common: ConfigPanel: Apply LineageOS rebrand
Change-Id: I33178e6bc605014033c498ad20c1224e8f4f007d
commit d1eaf445b0f0351f57a81ece523429c8bf85d1b9
Author: Bruno Martins <bgcngm@gmail.com>
Date: Mon May 1 16:05:43 2017 +0100
msm8996-common: ConfigPanel: Hide features if unsupported
* This is required for now as capricorn has a different
fingerprint driver
Change-Id: I9c2de516358fd9f1c747682f9232752cfae08c6c
commit 15bb2b153afa11492c72ff41f5b0f03a89e4d54a
Author: Bruno Martins <bgcngm@gmail.com>
Date: Mon Apr 3 23:33:47 2017 +0100
msm8996-common: ConfigPanel: Check if PocketMode is installed
* Because users like to play tricks
Change-Id: I84c8d5032ef3df5ab2889e957d9a5b6fc270c091
commit 48924c20d0bd54461b4854be9feebcc8584befd6
Author: Bruno Martins <bgcngm@gmail.com>
Date: Wed Mar 29 23:22:37 2017 +0100
msm8996-common: Allow control over PocketMode service
* Once the service is running, proximity sensor is constantly active
when the display is turned off, resulting into a residual increase
in battery consumption. Add a toggle so that users can decide whether
they accept that and prefer to prevent accidental wake-ups triggered
by the fingerprint sensor.
* Keep the receiver that listens for the screen status registered only
if the fingerprint wake-up feature is enabled at the same time as
the accidental wake-up prevention feature.
* Set PocketMode as a required module of ConfigPanel, to make sure
it is only shipped on devices building the latter.
Change-Id: I5941f445d0bd77be1efa9ffcde2d9854e6446c3d
commit c243b72bf0e5bd460167b7bb7d2f4286a5e4eea8
Author: LuK1337 <priv.luk@gmail.com>
Date: Wed Mar 29 18:09:37 2017 +0100
msm8996-common: ConfigPanel: Refactor
* Integrate more nicely with Settings
* Remove unnecessary permissions and unused resources
* Reorganize constants and helper methods
Change-Id: Id49e3aff5a243201cff5177de78cca26d932a055
commit b74788a08a571421d266e85d9fd384307fa6a86e
Author: Bruno Martins <bgcngm@gmail.com>
Date: Wed Mar 29 09:39:09 2017 +0000
msm8996-common: ConfigPanel: Use cmsdk FileUtils wherever it suits
* Use it in all cases where it suits and ensure that files
are writable before actually writing to them
Change-Id: If5c8da1cb80ecf24611b16f961343044939730af
commit 556a10de6c59ec8d9574e7c192324d8d8797e635
Author: Bruno Martins <bgcngm@gmail.com>
Date: Sat Mar 25 11:08:28 2017 +0000
msm8996-common: Integrate KeyHandler into ConfigPanel
* KeyHandler is device-specific (gemini only), but can't really work
without ConfigPanel, so merge into a single package
* On the other hand, move the overlays out of the common tree to allow other
devices to build ConfigPanel without being forced to use the KeyHandler
Change-Id: I0236ceca21ae47657d43868a4217e3db4699346e
commit 56e7f66124457e4df5878708815b164e0d006e26
Author: Bruno Martins <bgcngm@gmail.com>
Date: Thu Jan 5 15:49:09 2017 +0000
gemini: ConfigPanel: Commonize strings translations
* Translations moved to the new project
android_packages_resources_devicesettings
Change-Id: Ic840f76dac5c77d1bd680853ef77d57576d0953f
commit ceaa154c2f38ba3cdbc73c93acc089025f127059
Author: Bruno Martins <bgcngm@gmail.com>
Date: Wed Dec 14 10:47:49 2016 +0000
gemini: Support fingerprint as home button
* Take advantage of the fact that Xiaomi's fingerprint HAL
now sends KEY_KPENTER (keycode 96) and interpret it as
KEYCODE_HOME (keycode 102) - a home key event
* The ability to wake up device using home button can also be enabled
again because the fingerprint HAL sends key 96 only when
device is turned on and unlocked
Change-Id: I29782b73a62724e5b706d6edf366d180893f2ce9
commit 0c7f6b822b25da07b8707238e3e42295a7a5ac5d
Author: Bruno Martins <bgcngm@gmail.com>
Date: Sat Jan 7 21:14:20 2017 +0000
gemini: ConfigPanel: Remove unused code
Change-Id: I14a48c4ab1b138bfba93d0508764b748f5dc9009
commit 0b3629400152a73744ff097f64c5776fa49d8f80
Author: Louis Popi <theh2o64@gmail.com>
Date: Thu Dec 15 19:46:37 2016 +0100
gemini: Add fingerprint wakeup option
* This allows the users to chose whether fingerprint
wakes up the device
Change-Id: I6baa53d22293b741aade7a752ff90a0e5a8daaac
commit d5e6991feffc97b8a30cd9e305da62ac474a680f
Author: Willi Ye <williye97@gmail.com>
Date: Thu Dec 8 21:33:43 2016 +0100
gemini: ConfigPanel: Update colors to match SystemUI
Change-Id: Ia919e8e7d15ffd51573c43d143884ed6e7ce91f4
commit ec7fbbf61b586087f4bfae653be4092bd3febb31
Author: Steve Kondik <steve@cyngn.com>
Date: Wed Oct 5 01:19:59 2016 -0700
gemini: ConfigPanel: Fix bootup behavior
* Set the app as direct boot aware so we're able to receive
the magic broadcast from CMHardwareManager. Otherwise,
the boot-time initialization never runs.
Change-Id: I0018dd5265ace37e79b775ff62e4f0686f30fd40
commit 1e41ce03cb81af2e8b16bf0fb36de89372f53723
Author: Louis Popi <theh2o64@gmail.com>
Date: Thu Oct 20 19:38:27 2016 +0200
gemini: Add ConfigPanel for button swap
* Based on Oppo's implementation
Change-Id: Ia66fd3fed7cc1687862ab1d35578b525a422f0bb
* Full history at https://github.com/LineageOS/android_device_xiaomi_msm8996-common/tree/lineage-16.0/configpanel
Change-Id: If941135420bc10d93c0ad49e2fa7fe0cab82f1ad
Diffstat (limited to 'configpanel')
24 files changed, 876 insertions, 0 deletions
diff --git a/configpanel/Android.mk b/configpanel/Android.mk new file mode 100644 index 0000000..5e2fdd0 --- /dev/null +++ b/configpanel/Android.mk @@ -0,0 +1,32 @@ +LOCAL_PATH := $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := $(call all-java-files-under, src) +LOCAL_CERTIFICATE := platform +LOCAL_PRIVILEGED_MODULE := true +LOCAL_PACKAGE_NAME := ConfigPanel +LOCAL_PRIVATE_PLATFORM_APIS := true +LOCAL_REQUIRED_MODULES := ZukPocketMode + +LOCAL_USE_AAPT2 := true + +LOCAL_STATIC_ANDROID_LIBRARIES := \ + android-support-v4 \ + android-support-v7-appcompat \ + android-support-v7-preference \ + android-support-v7-recyclerview \ + android-support-v13 \ + android-support-v14-preference \ + +LOCAL_STATIC_JAVA_LIBRARIES := \ + org.lineageos.platform.internal + +LOCAL_RESOURCE_DIR := \ + $(LOCAL_PATH)/res \ + $(TOP)/packages/resources/devicesettings/res + +LOCAL_PROGUARD_FLAG_FILES := proguard.flags + +LOCAL_MODULE_TAGS := optional + +include $(BUILD_PACKAGE) diff --git a/configpanel/AndroidManifest.xml b/configpanel/AndroidManifest.xml new file mode 100644 index 0000000..f62e7fc --- /dev/null +++ b/configpanel/AndroidManifest.xml @@ -0,0 +1,68 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2016 The CyanogenMod Project + Copyright (C) 2017-2018 The LineageOS Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="org.lineageos.settings.device" + android:versionCode="6" + android:versionName="2.5" + android:sharedUserId="android.uid.system"> + + <protected-broadcast android:name="org.lineageos.settings.device.CUST_UPDATE" /> + + <uses-permission android:name="lineageos.permission.HARDWARE_ABSTRACTION_ACCESS" /> + + <uses-sdk + android:minSdkVersion="27" /> + + <application + android:icon="@mipmap/ic_launcher" + android:label="@string/device_settings_app_name" + android:theme="@style/Theme.Main" + android:defaultToDeviceProtectedStorage="true" + android:directBootAware="true"> + + <provider + android:name=".ConfigPanelSearchIndexablesProvider" + android:authorities="org.lineageos.settings.device" + android:multiprocess="false" + android:grantUriPermissions="true" + android:permission="android.permission.READ_SEARCH_INDEXABLES" + android:exported="true"> + <intent-filter> + <action android:name="android.content.action.SEARCH_INDEXABLES_PROVIDER" /> + </intent-filter> + </provider> + + <activity + android:name=".ButtonSettingsActivity" + android:label="@string/button_panel_title"> + <intent-filter> + <action android:name="org.lineageos.settings.device.ADDITIONAL_BUTTONS_SETTINGS" /> + <category android:name="android.intent.category.DEFAULT" /> + </intent-filter> + </activity> + + <activity android:name=".KeyHandler" /> + + <receiver android:name=".Startup" > + <intent-filter> + <action android:name="lineageos.intent.action.INITIALIZE_LINEAGE_HARDWARE" /> + </intent-filter> + </receiver> + </application> + +</manifest> diff --git a/configpanel/proguard.flags b/configpanel/proguard.flags new file mode 100644 index 0000000..43b57d9 --- /dev/null +++ b/configpanel/proguard.flags @@ -0,0 +1,3 @@ +-keepclasseswithmembers class * { + public <init>(android.content.Context, android.util.AttributeSet); +} diff --git a/configpanel/res/drawable/ic_settings_additional_buttons.xml b/configpanel/res/drawable/ic_settings_additional_buttons.xml new file mode 100644 index 0000000..044fc23 --- /dev/null +++ b/configpanel/res/drawable/ic_settings_additional_buttons.xml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (c) 2016 The CyanogenMod Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24" + android:viewportHeight="24"> + + <path + android:fillColor="@android:color/white" + android:pathData="M17,1L7,1C5.9,1,5,1.9,5,3v2h2v4H5v12c0,1.1,0.9,2,2,2h10c1.1,0,2-0.9,2-2V3C19,1.9,18.1,1,17,1z +M11,21H7v-2h4V21z M17,21 h-4v-2h4V21z" /> +</vector> diff --git a/configpanel/res/mipmap-anydpi/ic_launcher.xml b/configpanel/res/mipmap-anydpi/ic_launcher.xml new file mode 100644 index 0000000..d8649ba --- /dev/null +++ b/configpanel/res/mipmap-anydpi/ic_launcher.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (c) 2018 The LineageOS Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> + <background android:drawable="@mipmap/ic_background"/> + <foreground android:drawable="@mipmap/ic_foreground"/> +</adaptive-icon> + diff --git a/configpanel/res/mipmap-hdpi/ic_background.png b/configpanel/res/mipmap-hdpi/ic_background.png Binary files differnew file mode 100644 index 0000000..f01deeb --- /dev/null +++ b/configpanel/res/mipmap-hdpi/ic_background.png diff --git a/configpanel/res/mipmap-hdpi/ic_foreground.png b/configpanel/res/mipmap-hdpi/ic_foreground.png Binary files differnew file mode 100644 index 0000000..97158bc --- /dev/null +++ b/configpanel/res/mipmap-hdpi/ic_foreground.png diff --git a/configpanel/res/mipmap-mdpi/ic_background.png b/configpanel/res/mipmap-mdpi/ic_background.png Binary files differnew file mode 100644 index 0000000..58bcf52 --- /dev/null +++ b/configpanel/res/mipmap-mdpi/ic_background.png diff --git a/configpanel/res/mipmap-mdpi/ic_foreground.png b/configpanel/res/mipmap-mdpi/ic_foreground.png Binary files differnew file mode 100644 index 0000000..7b9bc07 --- /dev/null +++ b/configpanel/res/mipmap-mdpi/ic_foreground.png diff --git a/configpanel/res/mipmap-xhdpi/ic_background.png b/configpanel/res/mipmap-xhdpi/ic_background.png Binary files differnew file mode 100644 index 0000000..681a199 --- /dev/null +++ b/configpanel/res/mipmap-xhdpi/ic_background.png diff --git a/configpanel/res/mipmap-xhdpi/ic_foreground.png b/configpanel/res/mipmap-xhdpi/ic_foreground.png Binary files differnew file mode 100644 index 0000000..c079116 --- /dev/null +++ b/configpanel/res/mipmap-xhdpi/ic_foreground.png diff --git a/configpanel/res/mipmap-xxhdpi/ic_background.png b/configpanel/res/mipmap-xxhdpi/ic_background.png Binary files differnew file mode 100644 index 0000000..1e707e8 --- /dev/null +++ b/configpanel/res/mipmap-xxhdpi/ic_background.png diff --git a/configpanel/res/mipmap-xxhdpi/ic_foreground.png b/configpanel/res/mipmap-xxhdpi/ic_foreground.png Binary files differnew file mode 100644 index 0000000..ecc70af --- /dev/null +++ b/configpanel/res/mipmap-xxhdpi/ic_foreground.png diff --git a/configpanel/res/mipmap-xxxhdpi/ic_background.png b/configpanel/res/mipmap-xxxhdpi/ic_background.png Binary files differnew file mode 100644 index 0000000..b6e860b --- /dev/null +++ b/configpanel/res/mipmap-xxxhdpi/ic_background.png diff --git a/configpanel/res/mipmap-xxxhdpi/ic_foreground.png b/configpanel/res/mipmap-xxxhdpi/ic_foreground.png Binary files differnew file mode 100644 index 0000000..3133594 --- /dev/null +++ b/configpanel/res/mipmap-xxxhdpi/ic_foreground.png diff --git a/configpanel/res/values/styles.xml b/configpanel/res/values/styles.xml new file mode 100644 index 0000000..8dbdd4f --- /dev/null +++ b/configpanel/res/values/styles.xml @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2014-2016 The CyanogenMod Project + (C) 2017 The LineageOS Project + + Licensed under the Apache License, Version 2.0 (the "License" + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + <style name="Theme.Main" parent="@android:style/Theme.DeviceDefault.Settings"> + <item name="preferenceCategoryStyle">@style/Theme.Main.PreferenceCategoryStyle</item> + <item name="preferenceFragmentStyle">@style/Theme.Main.PreferenceFragmentStyle</item> + <item name="preferenceStyle">@style/Theme.Main.PreferenceStyle</item> + <item name="preferenceTheme">@style/Theme.Main.PreferenceTheme</item> + <item name="switchPreferenceStyle">@style/Theme.Main.SwitchPreferenceStyle</item> + </style> + + <style name="Theme.Main.PreferenceCategoryStyle" parent="@*android:style/Preference.DeviceDefault.Category"> + <item name="allowDividerAbove">true</item> + <item name="allowDividerBelow">true</item> + <item name="android:layout">@layout/preference_category_material_settings</item> + </style> + + <style name="Theme.Main.PreferenceFragmentStyle" parent="@*android:style/PreferenceFragment.Material"> + <item name="allowDividerAfterLastItem">false</item> + </style> + + <style name="Theme.Main.PreferenceStyle" parent="@*android:style/Preference.DeviceDefault"> + <item name="allowDividerAbove">false</item> + <item name="allowDividerBelow">true</item> + <item name="singleLineTitle">false</item> + <item name="android:layout">@layout/preference_material_settings</item> + </style> + + <style name="Theme.Main.PreferenceTheme"> + </style> + + <style name="Theme.Main.SwitchPreferenceStyle" parent="@style/Theme.Main.PreferenceStyle"> + <item name="widgetLayout">@*android:layout/preference_widget_switch</item> + </style> +</resources> diff --git a/configpanel/res/xml/button_panel.xml b/configpanel/res/xml/button_panel.xml new file mode 100644 index 0000000..43f4902 --- /dev/null +++ b/configpanel/res/xml/button_panel.xml @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2016 The CyanogenMod Project + (C) 2017 The LineageOS Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> + + <SwitchPreference + android:key="button_swap" + android:title="@string/button_swap_title" + android:summary="@string/button_swap_summary" /> + + <PreferenceCategory + android:key="fp_key" + android:title="@string/fingerprint_title" > + + <SwitchPreference + android:key="fp_home" + android:title="@string/fingerprint_as_home_title" + android:summary="@string/fingerprint_as_home_summary" /> + + <SwitchPreference + android:key="fp_wakeup" + android:title="@string/fingerprint_wakeup_title" + android:summary="@string/fingerprint_wakeup_summary" /> + + <SwitchPreference + android:key="fp_pocketmode" + android:title="@string/fingerprint_pocketmode_title" + android:summary="@string/fingerprint_pocketmode_summary" + android:dependency="fp_wakeup" /> + + </PreferenceCategory> + +</PreferenceScreen> diff --git a/configpanel/src/org/lineageos/settings/device/ButtonSettingsActivity.java b/configpanel/src/org/lineageos/settings/device/ButtonSettingsActivity.java new file mode 100644 index 0000000..737dbd5 --- /dev/null +++ b/configpanel/src/org/lineageos/settings/device/ButtonSettingsActivity.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2016 The CyanogenMod Project + * (C) 2017 The LineageOS Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.lineageos.settings.device; + +import android.os.Bundle; +import android.preference.PreferenceActivity; + +public class ButtonSettingsActivity extends PreferenceActivity { + + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + getFragmentManager().beginTransaction().replace(android.R.id.content, + new ButtonSettingsFragment()).commit(); + } +} diff --git a/configpanel/src/org/lineageos/settings/device/ButtonSettingsFragment.java b/configpanel/src/org/lineageos/settings/device/ButtonSettingsFragment.java new file mode 100644 index 0000000..b951641 --- /dev/null +++ b/configpanel/src/org/lineageos/settings/device/ButtonSettingsFragment.java @@ -0,0 +1,148 @@ +/* + * Copyright (C) 2016 The CyanogenMod Project + * (C) 2017 The LineageOS Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.lineageos.settings.device; + +import android.app.ActionBar; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.support.v14.preference.PreferenceFragment; +import android.support.v14.preference.SwitchPreference; +import android.support.v7.preference.ListPreference; +import android.support.v7.preference.Preference; +import android.support.v7.preference.Preference.OnPreferenceChangeListener; +import android.support.v7.preference.PreferenceCategory; +import android.support.v7.preference.PreferenceManager; +import android.text.TextUtils; +import android.view.MenuItem; + +import org.lineageos.internal.util.FileUtils; +import org.lineageos.internal.util.PackageManagerUtils; + +public class ButtonSettingsFragment extends PreferenceFragment + implements OnPreferenceChangeListener { + + @Override + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { + addPreferencesFromResource(R.xml.button_panel); + final ActionBar actionBar = getActivity().getActionBar(); + actionBar.setDisplayHomeAsUpEnabled(true); + } + + @Override + public void onResume() { + super.onResume(); + updatePreferencesBasedOnDependencies(); + } + + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); + + String node = Constants.sBooleanNodePreferenceMap.get(preference.getKey()); + if (!TextUtils.isEmpty(node) && FileUtils.isFileWritable(node)) { + Boolean value = (Boolean) newValue; + FileUtils.writeLine(node, value ? "1" : "0"); + if (Constants.FP_WAKEUP_KEY.equals(preference.getKey())) { + value &= prefs.getBoolean(Constants.FP_POCKETMODE_KEY, false); + Utils.broadcastCustIntent(getContext(), value); + } + return true; + } + node = Constants.sStringNodePreferenceMap.get(preference.getKey()); + if (!TextUtils.isEmpty(node) && FileUtils.isFileWritable(node)) { + FileUtils.writeLine(node, (String) newValue); + return true; + } + + if (Constants.FP_POCKETMODE_KEY.equals(preference.getKey())) { + Utils.broadcastCustIntent(getContext(), (Boolean) newValue); + return true; + } + + return false; + } + + @Override + public void addPreferencesFromResource(int preferencesResId) { + super.addPreferencesFromResource(preferencesResId); + // Initialize node preferences + for (String pref : Constants.sBooleanNodePreferenceMap.keySet()) { + SwitchPreference b = (SwitchPreference) findPreference(pref); + if (b == null) continue; + b.setOnPreferenceChangeListener(this); + String node = Constants.sBooleanNodePreferenceMap.get(pref); + if (FileUtils.isFileReadable(node)) { + String curNodeValue = FileUtils.readOneLine(node); + b.setChecked(curNodeValue.equals("1")); + } else { + b.setEnabled(false); + } + } + for (String pref : Constants.sStringNodePreferenceMap.keySet()) { + ListPreference l = (ListPreference) findPreference(pref); + if (l == null) continue; + l.setOnPreferenceChangeListener(this); + String node = Constants.sStringNodePreferenceMap.get(pref); + if (FileUtils.isFileReadable(node)) { + l.setValue(FileUtils.readOneLine(node)); + } else { + l.setEnabled(false); + } + } + + // Initialize other preferences whose keys are not associated with nodes + final PreferenceCategory fingerprintCategory = + (PreferenceCategory) getPreferenceScreen().findPreference(Constants.CATEGORY_FP); + + SwitchPreference b = (SwitchPreference) findPreference(Constants.FP_POCKETMODE_KEY); + if (!PackageManagerUtils.isAppInstalled(getContext(), "org.lineageos.pocketmode")) { + fingerprintCategory.removePreference(b); + } else { + b.setOnPreferenceChangeListener(this); + } + + // Hide fingerprint features if the device doesn't support them + if (!FileUtils.fileExists(Constants.FP_HOME_KEY_NODE) && + !FileUtils.fileExists(Constants.FP_WAKEUP_NODE)) { + getPreferenceScreen().removePreference(fingerprintCategory); + } + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (item.getItemId() == android.R.id.home) { + getActivity().onBackPressed(); + return true; + } + return false; + } + + private void updatePreferencesBasedOnDependencies() { + for (String pref : Constants.sNodeDependencyMap.keySet()) { + SwitchPreference b = (SwitchPreference) findPreference(pref); + if (b == null) continue; + String dependencyNode = Constants.sNodeDependencyMap.get(pref)[0]; + if (FileUtils.isFileReadable(dependencyNode)) { + String dependencyNodeValue = FileUtils.readOneLine(dependencyNode); + boolean shouldSetEnabled = dependencyNodeValue.equals( + Constants.sNodeDependencyMap.get(pref)[1]); + Utils.updateDependentPreference(getContext(), b, pref, shouldSetEnabled); + } + } + } +} diff --git a/configpanel/src/org/lineageos/settings/device/ConfigPanelSearchIndexablesProvider.java b/configpanel/src/org/lineageos/settings/device/ConfigPanelSearchIndexablesProvider.java new file mode 100644 index 0000000..c234791 --- /dev/null +++ b/configpanel/src/org/lineageos/settings/device/ConfigPanelSearchIndexablesProvider.java @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2016 The CyanogenMod Project + * (C) 2017-2018 The LineageOS Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.lineageos.settings.device; + +import android.content.Context; +import android.database.Cursor; +import android.database.MatrixCursor; +import android.provider.SearchIndexableResource; +import android.provider.SearchIndexablesProvider; + +import static android.provider.SearchIndexablesContract.COLUMN_INDEX_NON_INDEXABLE_KEYS_KEY_VALUE; +import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_CLASS_NAME; +import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_ICON_RESID; +import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_INTENT_ACTION; +import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_INTENT_TARGET_CLASS; +import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_INTENT_TARGET_PACKAGE; +import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_RANK; +import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_RESID; +import static android.provider.SearchIndexablesContract.INDEXABLES_RAW_COLUMNS; +import static android.provider.SearchIndexablesContract.INDEXABLES_XML_RES_COLUMNS; +import static android.provider.SearchIndexablesContract.NON_INDEXABLES_KEYS_COLUMNS; + +import org.lineageos.internal.util.FileUtils; +import org.lineageos.internal.util.PackageManagerUtils; + +import java.util.ArrayList; +import java.util.List; + +public class ConfigPanelSearchIndexablesProvider extends SearchIndexablesProvider { + private static final String TAG = "ConfigPanelSearchIndexablesProvider"; + + public static final int SEARCH_IDX_BUTTON_PANEL = 0; + + private static SearchIndexableResource[] INDEXABLE_RES = new SearchIndexableResource[]{ + new SearchIndexableResource(1, R.xml.button_panel, + ButtonSettingsActivity.class.getName(), + R.drawable.ic_settings_additional_buttons), + }; + + @Override + public boolean onCreate() { + return true; + } + + @Override + public Cursor queryXmlResources(String[] projection) { + MatrixCursor cursor = new MatrixCursor(INDEXABLES_XML_RES_COLUMNS); + if (Startup.hasButtonProcs() /* show button panel */) { + cursor.addRow(generateResourceRef(INDEXABLE_RES[SEARCH_IDX_BUTTON_PANEL])); + } + return cursor; + } + + private static Object[] generateResourceRef(SearchIndexableResource sir) { + final Object[] ref = new Object[INDEXABLES_XML_RES_COLUMNS.length]; + ref[COLUMN_INDEX_XML_RES_RANK] = sir.rank; + ref[COLUMN_INDEX_XML_RES_RESID] = sir.xmlResId; + ref[COLUMN_INDEX_XML_RES_CLASS_NAME] = null; + ref[COLUMN_INDEX_XML_RES_ICON_RESID] = sir.iconResId; + ref[COLUMN_INDEX_XML_RES_INTENT_ACTION] = "com.android.settings.action.EXTRA_SETTINGS"; + ref[COLUMN_INDEX_XML_RES_INTENT_TARGET_PACKAGE] = "org.lineageos.settings.device"; + ref[COLUMN_INDEX_XML_RES_INTENT_TARGET_CLASS] = sir.className; + return ref; + } + + private List<String> getNonIndexableKeys(Context context) { + List<String> keys = new ArrayList<>(); + if (!PackageManagerUtils.isAppInstalled(context, "org.lineageos.pocketmode")) { + keys.add(Constants.FP_POCKETMODE_KEY); + } + if (!FileUtils.fileExists(Constants.FP_HOME_KEY_NODE) && + !FileUtils.fileExists(Constants.FP_WAKEUP_NODE)) { + keys.add(Constants.FP_HOME_KEY); + keys.add(Constants.FP_WAKEUP_KEY); + } + return keys; + } + + @Override + public Cursor queryRawData(String[] projection) { + MatrixCursor cursor = new MatrixCursor(INDEXABLES_RAW_COLUMNS); + return cursor; + } + + @Override + public Cursor queryNonIndexableKeys(String[] projection) { + MatrixCursor cursor = new MatrixCursor(NON_INDEXABLES_KEYS_COLUMNS); + final Context context = getContext(); + + List<String> nonIndexableKeys = getNonIndexableKeys(context); + for (String nik : nonIndexableKeys) { + final Object[] ref = new Object[NON_INDEXABLES_KEYS_COLUMNS.length]; + ref[COLUMN_INDEX_NON_INDEXABLE_KEYS_KEY_VALUE] = nik; + cursor.addRow(ref); + } + return cursor; + } +} diff --git a/configpanel/src/org/lineageos/settings/device/Constants.java b/configpanel/src/org/lineageos/settings/device/Constants.java new file mode 100644 index 0000000..b673946 --- /dev/null +++ b/configpanel/src/org/lineageos/settings/device/Constants.java @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2016 The CyanogenMod Project + * (C) 2017-2018 The LineageOS Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.lineageos.settings.device; + +import org.lineageos.internal.util.FileUtils; + +import java.util.HashMap; +import java.util.Map; + +public class Constants { + + // Category keys + public static final String CATEGORY_FP = "fp_key"; + + // Preference keys + public static final String BUTTON_SWAP_KEY = "button_swap"; + public static final String FP_HOME_KEY = "fp_home"; + public static final String FP_POCKETMODE_KEY = "fp_pocketmode"; + public static final String FP_WAKEUP_KEY = "fp_wakeup"; + + // Nodes + public static final String CYTTSP_BUTTON_SWAP_NODE = "/proc/buttons/reversed_keys_enable"; + public static final String FP_HOME_KEY_NODE = "/sys/devices/soc/soc:fpc_fpc1020/enable_key_events"; + public static final String FP_WAKEUP_NODE = "/sys/devices/soc/soc:fpc_fpc1020/enable_wakeup"; + public static final String TOUCHPANEL_BUTTON_SWAP_NODE = "/proc/touchpanel/reversed_keys_enable"; + public static final String VIRTUAL_KEYS_NODE = "/proc/touchpanel/capacitive_keys_enable"; + + // Intents + public static final String CUST_INTENT = "org.lineageos.settings.device.CUST_UPDATE"; + public static final String CUST_INTENT_EXTRA = "pocketmode_service"; + + // Holds <preference_key> -> <proc_node> mapping + public static final Map<String, String> sBooleanNodePreferenceMap = new HashMap<>(); + public static final Map<String, String> sStringNodePreferenceMap = new HashMap<>(); + + // Holds <preference_key> -> <default_values> mapping + public static final Map<String, Object> sNodeDefaultMap = new HashMap<>(); + + // Holds <preference_key> -> <user_set_values> mapping + public static final Map<String, Object[]> sNodeUserSetValuesMap = new HashMap<>(); + + // Holds <preference_key> -> <dependency_check> mapping + public static final Map<String, String[]> sNodeDependencyMap = new HashMap<>(); + + public static final String[] sButtonPrefKeys = { + BUTTON_SWAP_KEY, + FP_HOME_KEY, + FP_WAKEUP_KEY + }; + + static { + if (FileUtils.fileExists(Constants.CYTTSP_BUTTON_SWAP_NODE)) { + sBooleanNodePreferenceMap.put(BUTTON_SWAP_KEY, CYTTSP_BUTTON_SWAP_NODE); + } else if (FileUtils.fileExists(Constants.TOUCHPANEL_BUTTON_SWAP_NODE)) { + sBooleanNodePreferenceMap.put(BUTTON_SWAP_KEY, TOUCHPANEL_BUTTON_SWAP_NODE); + } + sBooleanNodePreferenceMap.put(FP_HOME_KEY, FP_HOME_KEY_NODE); + sBooleanNodePreferenceMap.put(FP_WAKEUP_KEY, FP_WAKEUP_NODE); + + sNodeDefaultMap.put(BUTTON_SWAP_KEY, false); + sNodeDefaultMap.put(FP_HOME_KEY, false); + sNodeDefaultMap.put(FP_WAKEUP_KEY, true); + + sNodeDependencyMap.put(FP_HOME_KEY, new String[]{ VIRTUAL_KEYS_NODE, "1" }); + } +} diff --git a/configpanel/src/org/lineageos/settings/device/KeyHandler.java b/configpanel/src/org/lineageos/settings/device/KeyHandler.java new file mode 100644 index 0000000..247624b --- /dev/null +++ b/configpanel/src/org/lineageos/settings/device/KeyHandler.java @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2017-2019 The LineageOS Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.lineageos.settings.device; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.os.UserHandle; +import android.provider.Settings; +import android.util.Log; +import android.view.KeyEvent; + +import com.android.internal.os.DeviceKeyHandler; + +import lineageos.providers.LineageSettings; + +import org.lineageos.internal.util.FileUtils; + +public class KeyHandler implements DeviceKeyHandler { + + private static final String TAG = KeyHandler.class.getSimpleName(); + + private static final String FP_HOME_NODE = "/sys/devices/soc/soc:fpc_fpc1020/enable_key_events"; + + private static boolean sScreenTurnedOn = true; + private static final boolean DEBUG = false; + + private final Context mContext; + + private final BroadcastReceiver mScreenStateReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) { + sScreenTurnedOn = false; + } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) { + sScreenTurnedOn = true; + } + } + }; + + public KeyHandler(Context context) { + mContext = context; + + IntentFilter screenStateFilter = new IntentFilter(); + screenStateFilter.addAction(Intent.ACTION_SCREEN_OFF); + screenStateFilter.addAction(Intent.ACTION_SCREEN_ON); + mContext.registerReceiver(mScreenStateReceiver, screenStateFilter); + } + + public KeyEvent handleKeyEvent(KeyEvent event) { + boolean virtualKeysEnabled = LineageSettings.System.getIntForUser( + mContext.getContentResolver(), + LineageSettings.System.FORCE_SHOW_NAVBAR, 0, UserHandle.USER_CURRENT) != 0; + boolean fingerprintHomeButtonEnabled = FileUtils.isFileReadable(FP_HOME_NODE) && + FileUtils.readOneLine(FP_HOME_NODE).equals("1"); + + if (!hasSetupCompleted()) { + return event; + } + + if (event.getKeyCode() == KeyEvent.KEYCODE_HOME) { + if (event.getScanCode() == 96) { + if (DEBUG) Log.d(TAG, "Fingerprint home button tapped"); + return virtualKeysEnabled ? null : event; + } + if (event.getScanCode() == 102) { + if (DEBUG) Log.d(TAG, "Mechanical home button pressed"); + return sScreenTurnedOn && + (virtualKeysEnabled || fingerprintHomeButtonEnabled) ? null : event; + } + } + return event; + } + + private boolean hasSetupCompleted() { + return Settings.Secure.getInt(mContext.getContentResolver(), + Settings.Secure.USER_SETUP_COMPLETE, 0) != 0; + } +} diff --git a/configpanel/src/org/lineageos/settings/device/Startup.java b/configpanel/src/org/lineageos/settings/device/Startup.java new file mode 100644 index 0000000..4311cb5 --- /dev/null +++ b/configpanel/src/org/lineageos/settings/device/Startup.java @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2016 The CyanogenMod Project + * (C) 2017-2018 The LineageOS Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.lineageos.settings.device; + +import android.content.BroadcastReceiver; +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.SharedPreferences; +import android.support.v7.preference.PreferenceManager; +import android.util.Log; + +import org.lineageos.internal.util.FileUtils; + +public class Startup extends BroadcastReceiver { + + private static final String TAG = Startup.class.getSimpleName(); + + @Override + public void onReceive(Context context, Intent intent) { + final String action = intent.getAction(); + if (lineageos.content.Intent.ACTION_INITIALIZE_LINEAGE_HARDWARE.equals(action)) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + + // Disable button settings if needed + if (!hasButtonProcs()) { + disableComponent(context, ButtonSettingsActivity.class.getName()); + } else { + enableComponent(context, ButtonSettingsActivity.class.getName()); + + // Restore nodes to saved preference values + for (String pref : Constants.sButtonPrefKeys) { + String node, value; + if (Constants.sStringNodePreferenceMap.containsKey(pref)) { + node = Constants.sStringNodePreferenceMap.get(pref); + value = Utils.getPreferenceString(context, pref); + } else { + node = Constants.sBooleanNodePreferenceMap.get(pref); + value = Utils.isPreferenceEnabled(context, pref) ? "1" : "0"; + } + if (!FileUtils.writeLine(node, value)) { + Log.w(TAG, "Write to node " + node + + " failed while restoring saved preference values"); + } + } + + // Send initial broadcasts + final boolean shouldEnablePocketMode = + prefs.getBoolean(Constants.FP_WAKEUP_KEY, false) && + prefs.getBoolean(Constants.FP_POCKETMODE_KEY, false); + Utils.broadcastCustIntent(context, shouldEnablePocketMode); + } + } + } + + static boolean hasButtonProcs() { + return (FileUtils.fileExists(Constants.CYTTSP_BUTTON_SWAP_NODE) || + FileUtils.fileExists(Constants.FP_HOME_KEY_NODE) || + FileUtils.fileExists(Constants.FP_WAKEUP_NODE) || + FileUtils.fileExists(Constants.TOUCHPANEL_BUTTON_SWAP_NODE)); + } + + private void disableComponent(Context context, String component) { + ComponentName name = new ComponentName(context, component); + PackageManager pm = context.getPackageManager(); + pm.setComponentEnabledSetting(name, + PackageManager.COMPONENT_ENABLED_STATE_DISABLED, + PackageManager.DONT_KILL_APP); + } + + private void enableComponent(Context context, String component) { + ComponentName name = new ComponentName(context, component); + PackageManager pm = context.getPackageManager(); + if (pm.getComponentEnabledSetting(name) + == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) { + pm.setComponentEnabledSetting(name, + PackageManager.COMPONENT_ENABLED_STATE_ENABLED, + PackageManager.DONT_KILL_APP); + } + } +} diff --git a/configpanel/src/org/lineageos/settings/device/Utils.java b/configpanel/src/org/lineageos/settings/device/Utils.java new file mode 100644 index 0000000..9b3b2d7 --- /dev/null +++ b/configpanel/src/org/lineageos/settings/device/Utils.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2016 The CyanogenMod Project + * (C) 2017 The LineageOS Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.lineageos.settings.device; + +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.UserHandle; +import android.support.v14.preference.SwitchPreference; +import android.support.v7.preference.PreferenceManager; + +public class Utils { + + public static boolean isPreferenceEnabled(Context context, String key) { + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); + return preferences.getBoolean(key, (Boolean) Constants.sNodeDefaultMap.get(key)); + } + + public static String getPreferenceString(Context context, String key) { + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); + return preferences.getString(key, (String) Constants.sNodeDefaultMap.get(key)); + } + + public static void updateDependentPreference(Context context, SwitchPreference b, + String key, boolean shouldSetEnabled) { + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); + boolean prefActualValue = preferences.getBoolean(key, false); + + if (shouldSetEnabled) { + if (Constants.sNodeUserSetValuesMap.get(key) != null && + (Boolean) Constants.sNodeUserSetValuesMap.get(key)[1] && + (Boolean) Constants.sNodeUserSetValuesMap.get(key)[1] != prefActualValue) { + b.setChecked(true); + Constants.sNodeUserSetValuesMap.put(key, new Boolean[]{ prefActualValue, false }); + } + } else { + if (b.isEnabled() && prefActualValue) { + Constants.sNodeUserSetValuesMap.put(key, new Boolean[]{ prefActualValue, true }); + } + b.setEnabled(false); + b.setChecked(false); + } + } + + public static void broadcastCustIntent(Context context, boolean value) { + final Intent intent = new Intent(Constants.CUST_INTENT); + intent.putExtra(Constants.CUST_INTENT_EXTRA, value); + context.sendBroadcastAsUser(intent, UserHandle.CURRENT); + } +} |