AmbientDisplay: Add custom pref for devices with custom doze packages

Change-Id: Ie065f3892360f56d930ad1a373547454fb80892b
Signed-off-by: jhenrique09 <jhenrique09.mcz@hotmail.com>
Signed-off-by: HeroBuxx <me@herobuxx.me>
This commit is contained in:
jhenrique09
2024-05-05 11:01:15 +00:00
committed by Joey
parent f840809b4c
commit 9d62214276
4 changed files with 84 additions and 0 deletions

View File

@@ -70,4 +70,7 @@
<!-- Whether to show volume steps settings -->
<bool name="config_supports_volume_steps" translatable="false">true</bool>
<!-- Device specific doze package -->
<string name="config_customDozePackage" translatable="false"></string>
</resources>

View File

@@ -151,6 +151,10 @@
<intent android:action="org.lineageos.settings.device.DOZE_SETTINGS" />
</lineageos.preference.RemotePreference>
<Preference
android:key="ambient_display_custom"
android:title="@string/advanced_settings" />
</PreferenceCategory>
<!-- Work profile settings are at the bottom with high order value to avoid users thinking that

View File

@@ -0,0 +1,75 @@
/*
* Copyright (C) 2016 The Android Open Source 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.settings.display;
import android.content.Context;
import android.content.Intent;
import android.content.ComponentName;
import com.android.settings.R;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import androidx.preference.Preference;
import java.util.List;
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.ACTION_AMBIENT_DISPLAY;
public class AmbientDisplayCustomPreferenceController extends AbstractPreferenceController implements PreferenceControllerMixin {
static final String KEY_AMBIENT_CUSTOM = "ambient_display_custom";
private final MetricsFeatureProvider mMetricsFeatureProvider;
public AmbientDisplayCustomPreferenceController(Context context) {
super(context);
mMetricsFeatureProvider = FeatureFactory.getFeatureFactory().getMetricsFeatureProvider();
}
@Override
public boolean isAvailable() {
return !mContext.getResources().getString(R.string.config_customDozePackage).equals("");
}
@Override
public String getPreferenceKey() {
return KEY_AMBIENT_CUSTOM;
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
if (KEY_AMBIENT_CUSTOM.equals(preference.getKey())) {
mMetricsFeatureProvider.action(mContext, ACTION_AMBIENT_DISPLAY);
try {
String[] customDozePackage = mContext.getResources().getString(R.string.config_customDozePackage).split("/");
String activityName = customDozePackage[0];
String className = customDozePackage[1];
Intent intent = new Intent();
intent.setComponent(new ComponentName(activityName, className));
mContext.startActivity(intent);
} catch (Exception e){
}
}
return false;
}
@Override
public void updateNonIndexableKeys(List<String> keys) {
keys.add(getPreferenceKey());
}
}

View File

@@ -38,6 +38,7 @@ import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.display.AmbientDisplayAlwaysOnPreferenceController;
import com.android.settings.display.AmbientDisplayCustomPreferenceController;
import com.android.settings.display.AmbientDisplayNotificationsPreferenceController;
import com.android.settings.display.AODSchedulePreferenceController;
import com.android.settings.gestures.DoubleTapScreenPreferenceController;
@@ -134,6 +135,7 @@ public class LockscreenDashboardFragment extends DashboardFragment
use(DoubleTapScreenPreferenceController.class).setConfig(getConfig(context));
use(PickupGesturePreferenceController.class).setConfig(getConfig(context));
use(AODSchedulePreferenceController.class).setConfig(getConfig(context));
addPreferenceController(new AmbientDisplayCustomPreferenceController(context));
mControlsContentObserver = new ContentObserver(
new Handler(Looper.getMainLooper())) {