From dec73c392cf79c0453c2b26d5bcd1942070b7ef0 Mon Sep 17 00:00:00 2001 From: Tad Date: Fri, 10 Nov 2017 17:28:44 -0500 Subject: [PATCH] Add a qs tile for controlling radio power --- .../android_frameworks_base/0002-Radio.patch | 231 ++++++++++++++++++ .../cm_platform_sdk/0001-Radio.patch | 33 +++ Scripts/LineageOS-14.1/Patch.sh | 2 + 3 files changed, 266 insertions(+) create mode 100644 Patches/LineageOS-14.1/android_frameworks_base/0002-Radio.patch create mode 100644 Patches/LineageOS-14.1/cm_platform_sdk/0001-Radio.patch diff --git a/Patches/LineageOS-14.1/android_frameworks_base/0002-Radio.patch b/Patches/LineageOS-14.1/android_frameworks_base/0002-Radio.patch new file mode 100644 index 00000000..f6685cb1 --- /dev/null +++ b/Patches/LineageOS-14.1/android_frameworks_base/0002-Radio.patch @@ -0,0 +1,231 @@ +From 0eb8f3eb492844954cdbfa44b660cc5a278ebcd5 Mon Sep 17 00:00:00 2001 +From: Tad +Date: Fri, 10 Nov 2017 17:28:06 -0500 +Subject: [PATCH] Add radio power tile (1/2) + +Change-Id: Icec0f52b43d6bf319befa855a2dd753e9c99b98d +--- + packages/SystemUI/res/drawable/ic_qs_radio_off.xml | 10 ++ + packages/SystemUI/res/drawable/ic_qs_radio_on.xml | 10 ++ + packages/SystemUI/res/values/cm_strings.xml | 3 + + packages/SystemUI/res/values/config.xml | 2 +- + .../android/systemui/qs/tiles/RadioPowerTile.java | 127 +++++++++++++++++++++ + .../systemui/statusbar/phone/QSTileHost.java | 2 + + 6 files changed, 153 insertions(+), 1 deletion(-) + create mode 100644 packages/SystemUI/res/drawable/ic_qs_radio_off.xml + create mode 100644 packages/SystemUI/res/drawable/ic_qs_radio_on.xml + create mode 100644 packages/SystemUI/src/com/android/systemui/qs/tiles/RadioPowerTile.java + +diff --git a/packages/SystemUI/res/drawable/ic_qs_radio_off.xml b/packages/SystemUI/res/drawable/ic_qs_radio_off.xml +new file mode 100644 +index 00000000000..1cb49181faa +--- /dev/null ++++ b/packages/SystemUI/res/drawable/ic_qs_radio_off.xml +@@ -0,0 +1,10 @@ ++ ++ ++ ++ +diff --git a/packages/SystemUI/res/drawable/ic_qs_radio_on.xml b/packages/SystemUI/res/drawable/ic_qs_radio_on.xml +new file mode 100644 +index 00000000000..d446debdfc6 +--- /dev/null ++++ b/packages/SystemUI/res/drawable/ic_qs_radio_on.xml +@@ -0,0 +1,10 @@ ++ ++ ++ ++ +diff --git a/packages/SystemUI/res/values/cm_strings.xml b/packages/SystemUI/res/values/cm_strings.xml +index b429946bd93..89e3210a21f 100644 +--- a/packages/SystemUI/res/values/cm_strings.xml ++++ b/packages/SystemUI/res/values/cm_strings.xml +@@ -230,4 +230,7 @@ + Prevent %1$s from being dismissed + + Allow %1$s to be dismissed ++ ++ ++ Radio power + +diff --git a/packages/SystemUI/res/values/config.xml b/packages/SystemUI/res/values/config.xml +index 47aacddfbd3..fe98a33d00c 100644 +--- a/packages/SystemUI/res/values/config.xml ++++ b/packages/SystemUI/res/values/config.xml +@@ -105,7 +105,7 @@ + + + +- wifi,cell,battery,dnd,flashlight,rotation,bt,airplane,nfc,location,hotspot,inversion,saver,work,cast,night,adb_network,ambient_display,caffeine,heads_up,sync,usb_tether,volume_panel,profiles ++ wifi,cell,battery,dnd,flashlight,rotation,bt,airplane,nfc,location,hotspot,inversion,saver,work,cast,night,adb_network,ambient_display,caffeine,heads_up,sync,usb_tether,volume_panel,profiles,radio_power + + + +diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/RadioPowerTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/RadioPowerTile.java +new file mode 100644 +index 00000000000..b907205025c +--- /dev/null ++++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/RadioPowerTile.java +@@ -0,0 +1,127 @@ ++/* ++ * Copyright (C) 2015 The CyanogenMod Project ++ * Copyright (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 com.android.systemui.qs.tiles; ++ ++import android.content.BroadcastReceiver; ++import android.content.Context; ++import android.content.Intent; ++import android.content.IntentFilter; ++import android.database.ContentObserver; ++import android.os.UserHandle; ++import android.provider.Settings; ++ ++import com.android.internal.logging.MetricsLogger; ++import com.android.internal.logging.MetricsProto.MetricsEvent; ++import com.android.internal.telephony.Phone; ++import com.android.internal.telephony.PhoneFactory; ++ ++import com.android.systemui.R; ++import com.android.systemui.qs.QSTile; ++ ++import android.telephony.ServiceState; ++ ++ ++/** Quick settings tile: RadioPower **/ ++public class RadioPowerTile extends QSTile { ++ ++ private boolean mListening; ++ ++ public RadioPowerTile(Host host) { ++ super(host); ++ } ++ ++ @Override ++ public boolean isAvailable() { ++ return PhoneFactory.getDefaultPhone() != null; ++ } ++ ++ @Override ++ public BooleanState newTileState() { ++ return new BooleanState(); ++ } ++ ++ @Override ++ protected void handleClick() { ++ refreshState(!getRadioState()); ++ } ++ ++ @Override ++ public Intent getLongClickIntent() { ++ return new Intent().setClassName("com.android.settings", "com.android.settings.RadioInfo"); ++ } ++ ++ @Override ++ protected void handleLongClick() { ++ mHost.startActivityDismissingKeyguard(getLongClickIntent()); ++ } ++ ++ @Override ++ protected void handleUpdateState(BooleanState state, Object arg) { ++ state.visible = true; ++ final boolean radioPower = arg instanceof Boolean ? (boolean) arg : getRadioState(); ++ state.value = radioPower; ++ state.label = mContext.getString(R.string.quick_settings_radio_power_label); ++ if(state.value) { ++ state.icon = ResourceIcon.get(R.drawable.ic_qs_radio_on); ++ } else { ++ state.icon = ResourceIcon.get(R.drawable.ic_qs_radio_off); ++ } ++ } ++ ++ @Override ++ public CharSequence getTileLabel() { ++ return mContext.getString(R.string.quick_settings_radio_power_label); ++ } ++ ++ @Override ++ public int getMetricsCategory() { ++ return MetricsEvent.QS_AIRPLANEMODE; ++ } ++ ++ private boolean getRadioState() { ++ final Phone phone = PhoneFactory.getDefaultPhone(); ++ return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; ++ } ++ ++ private void setRadioState(boolean enabled) { ++ final Phone phone = PhoneFactory.getDefaultPhone(); ++ phone.setRadioPower(enabled); ++ } ++ ++ public void setListening(boolean listening) { ++ if (mListening == listening) return; ++ mListening = listening; ++ if (listening) { ++ final IntentFilter filter = new IntentFilter(); ++ filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED); ++ mContext.registerReceiver(mReceiver, filter); ++ } else { ++ mContext.unregisterReceiver(mReceiver); ++ } ++ } ++ ++ private final BroadcastReceiver mReceiver = new BroadcastReceiver() { ++ @Override ++ public void onReceive(Context context, Intent intent) { ++ if (Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(intent.getAction())) { ++ refreshState(); ++ } ++ } ++ }; ++ ++} +diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java +index 7f8ef210b52..ac7fa6ab96c 100755 +--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java ++++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java +@@ -59,6 +59,7 @@ import com.android.systemui.qs.tiles.IntentTile; + import com.android.systemui.qs.tiles.LocationTile; + import com.android.systemui.qs.tiles.NfcTile; + import com.android.systemui.qs.tiles.NightDisplayTile; ++import com.android.systemui.qs.tiles.RadioPowerTile; + import com.android.systemui.qs.tiles.RotationLockTile; + import com.android.systemui.qs.tiles.SyncTile; + import com.android.systemui.qs.tiles.UsbTetherTile; +@@ -441,6 +442,7 @@ public class QSTileHost implements QSTile.Host, Tunable { + else if (tileSpec.equals("dnd")) return new DndTile(this); + else if (tileSpec.equals("inversion")) return new ColorInversionTile(this); + else if (tileSpec.equals("airplane")) return new AirplaneModeTile(this); ++ else if (tileSpec.equals("radio_power")) return new RadioPowerTile(this); + else if (tileSpec.equals("work")) return new WorkModeTile(this); + else if (tileSpec.equals("rotation")) return new RotationLockTile(this); + else if (tileSpec.equals("flashlight")) return new FlashlightTile(this); +-- +2.15.0 + diff --git a/Patches/LineageOS-14.1/cm_platform_sdk/0001-Radio.patch b/Patches/LineageOS-14.1/cm_platform_sdk/0001-Radio.patch new file mode 100644 index 00000000..181e1413 --- /dev/null +++ b/Patches/LineageOS-14.1/cm_platform_sdk/0001-Radio.patch @@ -0,0 +1,33 @@ +From d69062c3f395613090ae902e43622af312036515 Mon Sep 17 00:00:00 2001 +From: Tad +Date: Fri, 10 Nov 2017 12:50:12 -0500 +Subject: [PATCH] Add radio power tile (2/2) + +Change-Id: I97745fc43ff6af599d7d30a6fd7db9b2942b3247 +--- + sdk/src/java/org/cyanogenmod/internal/util/QSConstants.java | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/sdk/src/java/org/cyanogenmod/internal/util/QSConstants.java b/sdk/src/java/org/cyanogenmod/internal/util/QSConstants.java +index c5e62eb..8782128 100644 +--- a/sdk/src/java/org/cyanogenmod/internal/util/QSConstants.java ++++ b/sdk/src/java/org/cyanogenmod/internal/util/QSConstants.java +@@ -26,6 +26,7 @@ public class QSConstants { + public static final String TILE_INVERSION = "inversion"; + public static final String TILE_CELLULAR = "cell"; + public static final String TILE_AIRPLANE = "airplane"; ++ public static final String TILE_RADIO_POWER = "radio_power"; + public static final String TILE_ROTATION = "rotation"; + public static final String TILE_FLASHLIGHT = "flashlight"; + public static final String TILE_LOCATION = "location"; +@@ -71,6 +72,7 @@ public class QSConstants { + STATIC_TILES_AVAILABLE.add(TILE_BLUETOOTH); + STATIC_TILES_AVAILABLE.add(TILE_CELLULAR); + STATIC_TILES_AVAILABLE.add(TILE_AIRPLANE); ++ STATIC_TILES_AVAILABLE.add(TILE_RADIO_POWER); + STATIC_TILES_AVAILABLE.add(TILE_ROTATION); + STATIC_TILES_AVAILABLE.add(TILE_FLASHLIGHT); + STATIC_TILES_AVAILABLE.add(TILE_LOCATION); +-- +2.15.0 + diff --git a/Scripts/LineageOS-14.1/Patch.sh b/Scripts/LineageOS-14.1/Patch.sh index 6bd07c65..377cafa6 100755 --- a/Scripts/LineageOS-14.1/Patch.sh +++ b/Scripts/LineageOS-14.1/Patch.sh @@ -131,6 +131,7 @@ sed -i 's/DEFAULT_MAX_FILES = 1000;/DEFAULT_MAX_FILES = 0;/' services/core/java/ sed -i 's/com.android.messaging/org.smssecure.smssecure/' core/res/res/values/config.xml; #Change default SMS app to Silence #sed -i 's|config_permissionReviewRequired">false|config_permissionReviewRequired">true|' core/res/res/values/config.xml; #XXX: Super awesome, but breaks quick tiles patch -p1 < $patches"android_frameworks_base/0001-Reduced_Resolution.patch" #Allow reducing resolution to save power TODO: Add 800x480 +patch -p1 < $patches"android_frameworks_base/0002-Radio.patch" #Add a QS tile to control radio power patch -p1 < $patches"android_frameworks_base/0003-Signature_Spoofing.patch" #Allow packages to spoof their signature (MicroG) patch -p1 < $patches"android_frameworks_base/0005-Harden_Sig_Spoofing.patch" #Restrict signature spoofing to system apps signed with the platform key rm -rf packages/PrintRecommendationService; #App that just creates popups to install proprietary print apps @@ -230,6 +231,7 @@ enter "vendor/cmsdk" git fetch https://review.lineageos.org/LineageOS/cm_platform_sdk refs/changes/21/148321/14 && git cherry-pick FETCH_HEAD #network traffic awk -i inplace '!/WeatherManagerServiceBroker/' cm/res/res/values/config.xml; #Disable Weather cp $patches"cm_platform_sdk/profile_default.xml" cm/res/res/xml/profile_default.xml; #Replace default profiles with *way* better ones +patch -p1 < $patches"cm_platform_sdk/0001-Radio.patch" #Add a QS tile to control radio power sed -i 's/shouldUseOptimizations(weight)/true/' cm/lib/main/java/org/cyanogenmod/platform/internal/PerformanceManagerService.java; #Per app performance profiles fix # #END OF ROM CHANGES