diff options
author | Marko Man <darkobas@gmail.com> | 2018-04-18 13:22:52 +0200 |
---|---|---|
committer | alk3pInjection <webmaster@raspii.tech> | 2022-02-17 10:03:45 +0800 |
commit | 8b76dae8392cfef750f137e935fc01f0314a1090 (patch) | |
tree | 32f3a10e3c80aeba19f59414703d6c225b57f211 | |
parent | 692ae6d6c1714782d356cf665b262249ba96a443 (diff) |
SystemUI: Add AOD QS tile
Squashed with:
Author: Marko Man <darkobas@gmail.com>
Date: Wed Apr 18 13:22:52 2018 +0200
base: SystemUI: add qs AOD tile
Change-Id: I0d9948dbd48e309d8fcc9b2c33be8b17810dc5b0
Author: shagbag913 <sh4gbag913@gmail.com>
Date: Sun Mar 1 15:49:17 2020 -0500
AODTile: disable tile when power save mode is on
AOD is not allowed when power save mode is active, reflect that upon the
tile.
Signed-off-by: NurKeinNeid <mralexman3000@gmail.com>
Change-Id: I3fc7f2a33d25a1616e8df5698ca2bc2a23d45cbb
Author: Bruno Martins <bgcngm@gmail.com>
Date: Sun Apr 12 19:04:24 2020 +0100
AODTile: Explicitely disable long clicks
Returning null in the getLongClickIntent() method is not enough to disable
tile long clock and results in crashes:
E AndroidRuntime: FATAL EXCEPTION: main
E AndroidRuntime: Process: com.android.systemui, PID: 1391
E AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Intent.resolveTypeIfNeeded(android.content.ContentResolver)' on a null object reference
E AndroidRuntime: at android.app.ApplicationPackageManager.queryIntentActivitiesAsUser(ApplicationPackageManager.java:1062)
E AndroidRuntime: at com.android.systemui.ActivityIntentHelper.getTargetActivityInfo(ActivityIntentHelper.java:70)
E AndroidRuntime: at com.android.systemui.ActivityIntentHelper.wouldLaunchResolverActivity(ActivityIntentHelper.java:47)
E AndroidRuntime: at com.android.systemui.statusbar.phone.StatusBar.startActivityDismissingKeyguard(StatusBar.java:2724)
E AndroidRuntime: at com.android.systemui.statusbar.phone.StatusBar.startActivityDismissingKeyguard(StatusBar.java:2709)
E AndroidRuntime: at com.android.systemui.statusbar.phone.StatusBar.startActivityDismissingKeyguard(StatusBar.java:2716)
E AndroidRuntime: at com.android.systemui.statusbar.phone.StatusBar.handleStartActivityDismissingKeyguard(StatusBar.java:3159)
E AndroidRuntime: at com.android.systemui.statusbar.phone.StatusBar.lambda$postStartActivityDismissingKeyguard$26$StatusBar(StatusBar.java:3155)
E AndroidRuntime: at com.android.systemui.statusbar.phone.-$$Lambda$StatusBar$CSd9n4rtnrfFyOdT2eTFRNUO5xM.run(Unknown Source:4)
E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:883)
E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:100)
E AndroidRuntime: at android.os.Looper.loop(Looper.java:214)
E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7356)
E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:491)
E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Change-Id: Ia7d4da4723600c47bedbfeb4b9152924a50d52dd
Author: Bruno Martins <bgcngm@gmail.com>
Date: Tue Jun 9 21:47:24 2020 +0100
AODTile: Rewrite AOD setting handling
This fixes the tile status on clean installs, which was showing as
active despite AOD being disabled.
Change-Id: I148cfb34938165395bc52c830d1f2e374b5427df
Author: Luca Stefani <luca.stefani.ge1@gmail.com>
Date: Thu Mar 18 12:22:21 2021 +0100
SystemUI: AODTile: Use SecureSetting to change doze setting
Change-Id: Ic39d26ac8a37041b75862627a497274b24f3362c
Author: LuK1337 <priv.luk@gmail.com>
Date: Thu Mar 18 12:23:45 2021 +0100
SystemUI: AODTile: Actually start using SecureSetting
Change-Id: I37f0194fcb54db1cf3cae221f7f702d398834ced
Change-Id: I5249106fea3518e8fa69990d1aa13c21cc542cb1
5 files changed, 180 insertions, 1 deletions
diff --git a/packages/SystemUI/res/drawable/ic_qs_aod.xml b/packages/SystemUI/res/drawable/ic_qs_aod.xml new file mode 100644 index 000000000000..4bb2d4ac566b --- /dev/null +++ b/packages/SystemUI/res/drawable/ic_qs_aod.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="utf-8"?> +<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="#ffffff" + android:pathData="M17,19 L17,5 L7,5 L7,19 L17,19 M17,1 C18.1046,1,19,1.89543,19,3 L19,21 C19,22.1046,18.1046,23,17,23 L7,23 C5.89,23,5,22.1,5,21 L5,3 C5,1.89,5.89,1,7,1 L17,1 M9,7 L15,7 L15,9 L9,9 L9,7" /> +</vector> diff --git a/packages/SystemUI/res/values/config.xml b/packages/SystemUI/res/values/config.xml index e1448f55e113..387916294fd9 100644 --- a/packages/SystemUI/res/values/config.xml +++ b/packages/SystemUI/res/values/config.xml @@ -107,7 +107,7 @@ <!-- Tiles native to System UI. Order should match "quick_settings_tiles_default" --> <string name="quick_settings_tiles_stock" translatable="false"> - internet,wifi,cell,bt,flashlight,dnd,alarm,airplane,controls,wallet,rotation,battery,cast,screenrecord,mictoggle,cameratoggle,location,hotspot,inversion,saver,dark,work,night,reverse,reduce_brightness,ambient_display,caffeine,heads_up + internet,wifi,cell,bt,flashlight,dnd,alarm,airplane,controls,wallet,rotation,battery,cast,screenrecord,mictoggle,cameratoggle,location,hotspot,inversion,saver,dark,work,night,reverse,reduce_brightness,ambient_display,aod,caffeine,heads_up </string> <!-- The tiles to display in QuickSettings --> diff --git a/packages/SystemUI/res/values/ice_strings.xml b/packages/SystemUI/res/values/ice_strings.xml index 0370bfb7376a..36c1e3a2592c 100644 --- a/packages/SystemUI/res/values/ice_strings.xml +++ b/packages/SystemUI/res/values/ice_strings.xml @@ -23,6 +23,10 @@ <string name="accessibility_quick_settings_ambient_display_changed_off">Ambient display turned off.</string> <string name="accessibility_quick_settings_ambient_display_changed_on">Ambient display turned on.</string> + <!-- AOD QS tile --> + <string name="quick_settings_aod_label">AOD</string> + <string name="quick_settings_aod_off_powersave_label">AOD off\nBattery saver</string> + <!-- Caffeine QS tile --> <string name="quick_settings_caffeine_label">Caffeine</string> <string name="accessibility_quick_settings_caffeine_off">Caffeine off.</string> diff --git a/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSFactoryImpl.java b/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSFactoryImpl.java index 6b99359a374f..7a18353792ee 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSFactoryImpl.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSFactoryImpl.java @@ -28,6 +28,7 @@ import com.android.systemui.qs.external.CustomTile; import com.android.systemui.qs.tiles.AirplaneModeTile; import com.android.systemui.qs.tiles.AlarmTile; import com.android.systemui.qs.tiles.AmbientDisplayTile; +import com.android.systemui.qs.tiles.AODTile; import com.android.systemui.qs.tiles.BatterySaverTile; import com.android.systemui.qs.tiles.BluetoothTile; import com.android.systemui.qs.tiles.CaffeineTile; @@ -94,6 +95,7 @@ public class QSFactoryImpl implements QSFactory { private final Provider<AlarmTile> mAlarmTileProvider; private final Provider<QuickAccessWalletTile> mQuickAccessWalletTileProvider; private final Provider<AmbientDisplayTile> mAmbientDisplayTileProvider; + private final Provider<AODTile> mAODTileProvider; private final Provider<CaffeineTile> mCaffeineTileProvider; private final Provider<HeadsUpTile> mHeadsUpTileProvider; @@ -132,6 +134,7 @@ public class QSFactoryImpl implements QSFactory { Provider<AlarmTile> alarmTileProvider, Provider<QuickAccessWalletTile> quickAccessWalletTileProvider, Provider<AmbientDisplayTile> ambientDisplayTileProvider, + Provider<AODTile> aodTileProvider, Provider<CaffeineTile> caffeineTileProvider, Provider<HeadsUpTile> headsUpTileProvider) { mQsHostLazy = qsHostLazy; @@ -165,6 +168,7 @@ public class QSFactoryImpl implements QSFactory { mAlarmTileProvider = alarmTileProvider; mQuickAccessWalletTileProvider = quickAccessWalletTileProvider; mAmbientDisplayTileProvider = ambientDisplayTileProvider; + mAODTileProvider = aodTileProvider; mCaffeineTileProvider = caffeineTileProvider; mHeadsUpTileProvider = headsUpTileProvider; } @@ -236,6 +240,8 @@ public class QSFactoryImpl implements QSFactory { // Additional tiles. case "ambient_display": return mAmbientDisplayTileProvider.get(); + case "aod": + return mAODTileProvider.get(); case "caffeine": return mCaffeineTileProvider.get(); case "heads_up": diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/AODTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/AODTile.java new file mode 100644 index 000000000000..147d782a4469 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/AODTile.java @@ -0,0 +1,158 @@ +/* + * Copyright (C) 2018 The OmniROM Project + * 2020-2021 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.Intent; +import android.os.Handler; +import android.os.Looper; +import android.provider.Settings; +import android.service.quicksettings.Tile; +import android.view.View; + +import androidx.annotation.Nullable; + +import com.android.internal.logging.MetricsLogger; +import com.android.internal.logging.nano.MetricsProto.MetricsEvent; +import com.android.systemui.R; +import com.android.systemui.dagger.qualifiers.Background; +import com.android.systemui.dagger.qualifiers.Main; +import com.android.systemui.plugins.ActivityStarter; +import com.android.systemui.plugins.FalsingManager; +import com.android.systemui.plugins.qs.QSTile.BooleanState; +import com.android.systemui.plugins.statusbar.StatusBarStateController; +import com.android.systemui.qs.QSHost; +import com.android.systemui.qs.SecureSetting; +import com.android.systemui.qs.logging.QSLogger; +import com.android.systemui.qs.tileimpl.QSTileImpl; +import com.android.systemui.statusbar.policy.BatteryController; +import com.android.systemui.util.settings.SecureSettings; + +import javax.inject.Inject; + +public class AODTile extends QSTileImpl<BooleanState> implements + BatteryController.BatteryStateChangeCallback { + + private final Icon mIcon = ResourceIcon.get(R.drawable.ic_qs_aod); + private final BatteryController mBatteryController; + + private final SecureSetting mSetting; + + @Inject + public AODTile( + QSHost host, + @Background Looper backgroundLooper, + @Main Handler mainHandler, + FalsingManager falsingManager, + MetricsLogger metricsLogger, + StatusBarStateController statusBarStateController, + ActivityStarter activityStarter, + QSLogger qsLogger, + SecureSettings secureSettings, + BatteryController batteryController + ) { + super(host, backgroundLooper, mainHandler, falsingManager, metricsLogger, + statusBarStateController, activityStarter, qsLogger); + + mSetting = new SecureSetting(secureSettings, mHandler, Settings.Secure.DOZE_ALWAYS_ON) { + @Override + protected void handleValueChanged(int value, boolean observedChange) { + handleRefreshState(value); + } + }; + + mBatteryController = batteryController; + batteryController.observe(getLifecycle(), this); + } + + @Override + public void onPowerSaveChanged(boolean isPowerSave) { + refreshState(); + } + + @Override + protected void handleDestroy() { + super.handleDestroy(); + mSetting.setListening(false); + } + + @Override + public boolean isAvailable() { + return mContext.getResources().getBoolean( + com.android.internal.R.bool.config_dozeAlwaysOnDisplayAvailable); + } + + @Override + public BooleanState newTileState() { + BooleanState state = new BooleanState(); + state.handlesLongClick = false; + return state; + } + + @Override + public void handleSetListening(boolean listening) { + super.handleSetListening(listening); + mSetting.setListening(listening); + } + + @Override + protected void handleUserSwitch(int newUserId) { + mSetting.setUserId(newUserId); + handleRefreshState(mSetting.getValue()); + } + + @Override + protected void handleClick(@Nullable View view) { + mSetting.setValue(mState.value ? 0 : 1); + } + + @Override + public Intent getLongClickIntent() { + return null; + } + + @Override + public CharSequence getTileLabel() { + if (mBatteryController.isAodPowerSave()) { + return mContext.getString(R.string.quick_settings_aod_off_powersave_label); + } + return mContext.getString(R.string.quick_settings_aod_label); + } + + @Override + protected void handleUpdateState(BooleanState state, Object arg) { + final int value = arg instanceof Integer ? (Integer) arg : mSetting.getValue(); + final boolean enable = value != 0; + if (state.slash == null) { + state.slash = new SlashState(); + } + state.icon = mIcon; + state.value = enable; + state.slash.isSlashed = state.value; + state.label = mContext.getString(R.string.quick_settings_aod_label); + if (mBatteryController.isAodPowerSave()) { + state.state = Tile.STATE_UNAVAILABLE; + } else { + state.state = enable ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE; + } + } + + @Override + public int getMetricsCategory() { + return MetricsEvent.ICE; + } +} |