Merge 24Q4 (ab/12406339) into aosp-main-future
Bug: 370570306 Merged-In: Ie90e7495dd4a134538bae6e3e08eea0d02134b14 Change-Id: I20517e9ee410e95f2cbeb1247c0c0288ed9f006f
This commit is contained in:
@@ -16,33 +16,38 @@
|
||||
|
||||
package com.android.settings.development;
|
||||
|
||||
import static android.provider.Settings.Global.DEVELOPMENT_FORCE_DESKTOP_MODE_ON_EXTERNAL_DISPLAYS;
|
||||
import static android.provider.Settings.Global.DEVELOPMENT_OVERRIDE_DESKTOP_MODE_FEATURES;
|
||||
import static android.window.flags.DesktopModeFlags.ToggleOverride.fromSetting;
|
||||
import static android.window.flags.DesktopModeFlags.ToggleOverride.OVERRIDE_OFF;
|
||||
import static android.window.flags.DesktopModeFlags.ToggleOverride.OVERRIDE_ON;
|
||||
import static android.window.flags.DesktopModeFlags.ToggleOverride.OVERRIDE_UNSET;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
import android.window.flags.DesktopModeFlags.ToggleOverride;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.TwoStatePreference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
|
||||
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus;
|
||||
|
||||
/**
|
||||
* Preference controller to control Desktop mode features
|
||||
*/
|
||||
public class DesktopModePreferenceController extends DeveloperOptionsPreferenceController
|
||||
implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin,
|
||||
RebootConfirmationDialogHost {
|
||||
|
||||
private static final String FORCE_DESKTOP_MODE_KEY = "force_desktop_mode_on_external_displays";
|
||||
private static final String OVERRIDE_DESKTOP_MODE_FEATURES_KEY =
|
||||
"override_desktop_mode_features";
|
||||
|
||||
@VisibleForTesting
|
||||
static final int SETTING_VALUE_OFF = 0;
|
||||
@VisibleForTesting
|
||||
static final int SETTING_VALUE_ON = 1;
|
||||
|
||||
@Nullable private final DevelopmentSettingsDashboardFragment mFragment;
|
||||
@Nullable
|
||||
private final DevelopmentSettingsDashboardFragment mFragment;
|
||||
|
||||
public DesktopModePreferenceController(
|
||||
Context context, @Nullable DevelopmentSettingsDashboardFragment fragment) {
|
||||
@@ -51,40 +56,47 @@ public class DesktopModePreferenceController extends DeveloperOptionsPreferenceC
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return FORCE_DESKTOP_MODE_KEY;
|
||||
public boolean isAvailable() {
|
||||
return DesktopModeStatus.canShowDesktopModeDevOption(mContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
public String getPreferenceKey() {
|
||||
return OVERRIDE_DESKTOP_MODE_FEATURES_KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(@NonNull Preference preference, Object newValue) {
|
||||
final boolean isEnabled = (Boolean) newValue;
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
DEVELOPMENT_FORCE_DESKTOP_MODE_ON_EXTERNAL_DISPLAYS,
|
||||
isEnabled ? SETTING_VALUE_ON : SETTING_VALUE_OFF);
|
||||
if (isEnabled) {
|
||||
DEVELOPMENT_OVERRIDE_DESKTOP_MODE_FEATURES,
|
||||
isEnabled ? OVERRIDE_ON.getSetting() : OVERRIDE_OFF.getSetting());
|
||||
if (mFragment != null) {
|
||||
RebootConfirmationDialogFragment.show(
|
||||
mFragment, R.string.reboot_dialog_force_desktop_mode, this);
|
||||
mFragment, R.string.reboot_dialog_override_desktop_mode, this);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
DEVELOPMENT_FORCE_DESKTOP_MODE_ON_EXTERNAL_DISPLAYS, SETTING_VALUE_OFF);
|
||||
((TwoStatePreference) mPreference).setChecked(mode != SETTING_VALUE_OFF);
|
||||
// Use overridden state, if not present, then use default state
|
||||
final int overrideInt = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
DEVELOPMENT_OVERRIDE_DESKTOP_MODE_FEATURES, OVERRIDE_UNSET.getSetting());
|
||||
final ToggleOverride toggleOverride = fromSetting(overrideInt,
|
||||
OVERRIDE_UNSET);
|
||||
final boolean shouldDevOptionBeEnabled = switch (toggleOverride) {
|
||||
case OVERRIDE_OFF -> false;
|
||||
case OVERRIDE_ON -> true;
|
||||
case OVERRIDE_UNSET -> DesktopModeStatus.shouldDevOptionBeEnabledByDefault();
|
||||
};
|
||||
((TwoStatePreference) mPreference).setChecked(shouldDevOptionBeEnabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDeveloperOptionsSwitchDisabled() {
|
||||
super.onDeveloperOptionsSwitchDisabled();
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
DEVELOPMENT_FORCE_DESKTOP_MODE_ON_EXTERNAL_DISPLAYS, SETTING_VALUE_OFF);
|
||||
((TwoStatePreference) mPreference).setChecked(false);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
String getBuildType() {
|
||||
return Build.TYPE;
|
||||
DEVELOPMENT_OVERRIDE_DESKTOP_MODE_FEATURES, OVERRIDE_UNSET.getSetting());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.development;
|
||||
|
||||
import static android.provider.Settings.Global.DEVELOPMENT_FORCE_DESKTOP_MODE_ON_EXTERNAL_DISPLAYS;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.TwoStatePreference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
|
||||
|
||||
/**
|
||||
* Preference controller to control Desktop mode features on secondary display
|
||||
*/
|
||||
public class DesktopModeSecondaryDisplayPreferenceController extends
|
||||
DeveloperOptionsPreferenceController
|
||||
implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin,
|
||||
RebootConfirmationDialogHost {
|
||||
|
||||
private static final String ENABLE_DESKTOP_MODE_ON_SECONDARY_DISPLAY =
|
||||
"force_desktop_mode_on_external_displays";
|
||||
|
||||
@VisibleForTesting
|
||||
static final int SETTING_VALUE_OFF = 0;
|
||||
@VisibleForTesting
|
||||
static final int SETTING_VALUE_ON = 1;
|
||||
|
||||
@Nullable
|
||||
private final DevelopmentSettingsDashboardFragment mFragment;
|
||||
|
||||
public DesktopModeSecondaryDisplayPreferenceController(
|
||||
Context context, @Nullable DevelopmentSettingsDashboardFragment fragment) {
|
||||
super(context);
|
||||
mFragment = fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return ENABLE_DESKTOP_MODE_ON_SECONDARY_DISPLAY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
final boolean isEnabled = (Boolean) newValue;
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
DEVELOPMENT_FORCE_DESKTOP_MODE_ON_EXTERNAL_DISPLAYS,
|
||||
isEnabled ? SETTING_VALUE_ON : SETTING_VALUE_OFF);
|
||||
// Update freeform window support on device.
|
||||
// DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT setting enables freeform support on device
|
||||
// where it's not present by default.
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT,
|
||||
isEnabled ? SETTING_VALUE_ON : SETTING_VALUE_OFF);
|
||||
if (isEnabled && mFragment != null) {
|
||||
RebootConfirmationDialogFragment.show(
|
||||
mFragment, R.string.reboot_dialog_enable_desktop_mode_on_secondary_display,
|
||||
this);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
DEVELOPMENT_FORCE_DESKTOP_MODE_ON_EXTERNAL_DISPLAYS, SETTING_VALUE_OFF);
|
||||
((TwoStatePreference) mPreference).setChecked(mode != SETTING_VALUE_OFF);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDeveloperOptionsSwitchDisabled() {
|
||||
super.onDeveloperOptionsSwitchDisabled();
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
DEVELOPMENT_FORCE_DESKTOP_MODE_ON_EXTERNAL_DISPLAYS, SETTING_VALUE_OFF);
|
||||
((TwoStatePreference) mPreference).setChecked(false);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
String getBuildType() {
|
||||
return Build.TYPE;
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License
|
||||
*/
|
||||
|
||||
package com.android.settings.security;
|
||||
package com.android.settings.development;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settings.development;
|
||||
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
import static android.provider.Settings.Global.DEVELOPMENT_SETTINGS_ENABLED;
|
||||
import static android.service.quicksettings.TileService.ACTION_QS_TILE_PREFERENCES;
|
||||
import static android.view.flags.Flags.sensitiveContentAppProtectionApi;
|
||||
@@ -56,6 +57,7 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.biometrics.IdentityCheckBiometricErrorDialog;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.dashboard.RestrictedDashboardFragment;
|
||||
import com.android.settings.development.autofill.AutofillCategoryController;
|
||||
@@ -76,6 +78,7 @@ import com.android.settings.development.linuxterminal.LinuxTerminalPreferenceCon
|
||||
import com.android.settings.development.qstile.DevelopmentTiles;
|
||||
import com.android.settings.development.storage.SharedDataPreferenceController;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.password.ConfirmDeviceCredentialActivity;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.actionbar.SearchMenuController;
|
||||
import com.android.settings.widget.SettingsMainSwitchBar;
|
||||
@@ -100,11 +103,13 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
|
||||
NfcRebootDialog.OnNfcRebootDialogConfirmedListener, BluetoothSnoopLogHost {
|
||||
|
||||
private static final String TAG = "DevSettingsDashboard";
|
||||
@VisibleForTesting static final int REQUEST_BIOMETRIC_PROMPT = 100;
|
||||
|
||||
private final BluetoothA2dpConfigStore mBluetoothA2dpConfigStore =
|
||||
new BluetoothA2dpConfigStore();
|
||||
|
||||
private boolean mIsAvailable = true;
|
||||
private boolean mIsBiometricsAuthenticated;
|
||||
private SettingsMainSwitchBar mSwitchBar;
|
||||
private DevelopmentSwitchBarController mSwitchBarController;
|
||||
private List<AbstractPreferenceController> mPreferenceControllers = new ArrayList<>();
|
||||
@@ -216,6 +221,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
final ContentResolver cr = getContext().getContentResolver();
|
||||
mIsBiometricsAuthenticated = false;
|
||||
cr.registerContentObserver(mDevelopEnabled, false, mDeveloperSettingsObserver);
|
||||
|
||||
// Restore UI state based on whether developer options is enabled
|
||||
@@ -360,7 +366,27 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
|
||||
DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(getContext());
|
||||
if (isChecked != developmentEnabledState) {
|
||||
if (isChecked) {
|
||||
EnableDevelopmentSettingWarningDialog.show(this /* host */);
|
||||
final int userId = getContext().getUserId();
|
||||
|
||||
final Utils.BiometricStatus biometricAuthStatus =
|
||||
Utils.requestBiometricAuthenticationForMandatoryBiometrics(
|
||||
getContext(),
|
||||
mIsBiometricsAuthenticated,
|
||||
userId);
|
||||
if (biometricAuthStatus == Utils.BiometricStatus.OK) {
|
||||
mSwitchBar.setChecked(false);
|
||||
Utils.launchBiometricPromptForMandatoryBiometrics(this,
|
||||
REQUEST_BIOMETRIC_PROMPT,
|
||||
userId, false /* hideBackground */);
|
||||
} else if (biometricAuthStatus != Utils.BiometricStatus.NOT_ACTIVE) {
|
||||
mSwitchBar.setChecked(false);
|
||||
IdentityCheckBiometricErrorDialog.showBiometricErrorDialog(getActivity(),
|
||||
biometricAuthStatus, false /* twoFactorAuthentication */);
|
||||
} else {
|
||||
//Reset biometrics once enable dialog is shown
|
||||
mIsBiometricsAuthenticated = false;
|
||||
EnableDevelopmentSettingWarningDialog.show(this /* host */);
|
||||
}
|
||||
} else {
|
||||
final BluetoothA2dpHwOffloadPreferenceController a2dpController =
|
||||
getDevelopmentOptionsController(
|
||||
@@ -534,6 +560,16 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
boolean handledResult = false;
|
||||
if (requestCode == REQUEST_BIOMETRIC_PROMPT) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
mIsBiometricsAuthenticated = true;
|
||||
mSwitchBar.setChecked(true);
|
||||
} else if (resultCode
|
||||
== ConfirmDeviceCredentialActivity.BIOMETRIC_LOCKOUT_ERROR_RESULT) {
|
||||
IdentityCheckBiometricErrorDialog.showBiometricErrorDialog(getActivity(),
|
||||
Utils.BiometricStatus.LOCKOUT, false /* twoFactorAuthentication */);
|
||||
}
|
||||
}
|
||||
for (AbstractPreferenceController controller : mPreferenceControllers) {
|
||||
if (controller instanceof OnActivityResultListener) {
|
||||
// We do not break early because it is possible for multiple controllers to
|
||||
@@ -716,6 +752,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
|
||||
controllers.add(new ShowTapsPreferenceController(context));
|
||||
controllers.add(new PointerLocationPreferenceController(context));
|
||||
controllers.add(new ShowKeyPressesPreferenceController(context));
|
||||
controllers.add(new TouchpadVisualizerPreferenceController(context));
|
||||
controllers.add(new ShowSurfaceUpdatesPreferenceController(context));
|
||||
controllers.add(new ShowLayoutBoundsPreferenceController(context));
|
||||
controllers.add(new ShowHdrSdrRatioPreferenceController(context));
|
||||
@@ -750,6 +787,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
|
||||
controllers.add(new ResizableActivityPreferenceController(context));
|
||||
controllers.add(new FreeformWindowsPreferenceController(context, fragment));
|
||||
controllers.add(new DesktopModePreferenceController(context, fragment));
|
||||
controllers.add(new DesktopModeSecondaryDisplayPreferenceController(context, fragment));
|
||||
controllers.add(new NonResizableMultiWindowPreferenceController(context));
|
||||
controllers.add(new ShortcutManagerThrottlingPreferenceController(context));
|
||||
controllers.add(new EnableGnssRawMeasFullTrackingPreferenceController(context));
|
||||
|
||||
@@ -16,8 +16,9 @@
|
||||
|
||||
package com.android.settings.development;
|
||||
|
||||
import static android.content.pm.PackageManager.FEATURE_FREEFORM_WINDOW_MANAGEMENT;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -40,7 +41,8 @@ public class FreeformWindowsPreferenceController extends DeveloperOptionsPrefere
|
||||
@VisibleForTesting
|
||||
static final int SETTING_VALUE_ON = 1;
|
||||
|
||||
@Nullable private final DevelopmentSettingsDashboardFragment mFragment;
|
||||
@Nullable
|
||||
private final DevelopmentSettingsDashboardFragment mFragment;
|
||||
|
||||
public FreeformWindowsPreferenceController(
|
||||
Context context, @Nullable DevelopmentSettingsDashboardFragment fragment) {
|
||||
@@ -48,6 +50,13 @@ public class FreeformWindowsPreferenceController extends DeveloperOptionsPrefere
|
||||
mFragment = fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
// When devices have the system feature FEATURE_FREEFORM_WINDOW_MANAGEMENT, freeform
|
||||
// mode is enabled automatically, and this toggle is not needed.
|
||||
return !mContext.getPackageManager().hasSystemFeature(FEATURE_FREEFORM_WINDOW_MANAGEMENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return ENABLE_FREEFORM_SUPPORT_KEY;
|
||||
@@ -80,9 +89,4 @@ public class FreeformWindowsPreferenceController extends DeveloperOptionsPrefere
|
||||
Settings.Global.DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT, SETTING_VALUE_OFF);
|
||||
((TwoStatePreference) mPreference).setChecked(false);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
String getBuildType() {
|
||||
return Build.TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,3 +16,6 @@ per-file DesktopModePreferenceController.java=file:platform/frameworks/base:/lib
|
||||
# ADB
|
||||
per-file Adb*=set noparent
|
||||
per-file Adb*=file:platform/packages/modules/adb:/OWNERS
|
||||
|
||||
#TouchpadVisualizerPreferenceController
|
||||
per-file TouchpadVisualizerPreferenceController.java=file:platform/frameworks/base:/INPUT_OWNERS
|
||||
|
||||
@@ -21,6 +21,7 @@ import android.app.settings.SettingsEnums;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
@@ -57,7 +58,8 @@ public class RebootConfirmationDialogFragment extends InstrumentedDialogFragment
|
||||
}
|
||||
}
|
||||
|
||||
private RebootConfirmationDialogFragment(
|
||||
@VisibleForTesting
|
||||
RebootConfirmationDialogFragment(
|
||||
int messageId, int cancelButtonId, RebootConfirmationDialogHost host) {
|
||||
mMessageId = messageId;
|
||||
mCancelButtonId = cancelButtonId;
|
||||
@@ -92,4 +94,11 @@ public class RebootConfirmationDialogFragment extends InstrumentedDialogFragment
|
||||
super.onDismiss(dialog);
|
||||
mHost.onRebootDialogDismissed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
dismiss();
|
||||
|
||||
super.onPause();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2024 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.development;
|
||||
|
||||
import android.content.Context;
|
||||
import android.hardware.input.InputSettings;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
|
||||
|
||||
/** PreferenceController that controls the "Show touchpad input" developer option. */
|
||||
public class TouchpadVisualizerPreferenceController extends
|
||||
DeveloperOptionsPreferenceController implements
|
||||
Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
|
||||
|
||||
private static final String TOUCHPAD_VISUALIZER_KEY = "touchpad_visualizer";
|
||||
|
||||
public TouchpadVisualizerPreferenceController(@NonNull Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull String getPreferenceKey() {
|
||||
return TOUCHPAD_VISUALIZER_KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(){
|
||||
return InputSettings.isTouchpadVisualizerFeatureFlagEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(@NonNull Preference preference, @Nullable Object newValue) {
|
||||
final boolean isEnabled = newValue != null ? (Boolean) newValue : false;
|
||||
InputSettings.setTouchpadVisualizer(mContext, isEnabled);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(@NonNull Preference preference) {
|
||||
boolean touchpadVisualizerEnabled = InputSettings.useTouchpadVisualizer(mContext);
|
||||
((SwitchPreference) mPreference).setChecked(touchpadVisualizerEnabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDeveloperOptionsSwitchDisabled() {
|
||||
super.onDeveloperOptionsSwitchDisabled();
|
||||
InputSettings.setTouchpadVisualizer(mContext, false);
|
||||
|
||||
((SwitchPreference) mPreference).setChecked(false);
|
||||
}
|
||||
}
|
||||
@@ -30,85 +30,184 @@ import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
|
||||
|
||||
/**
|
||||
* This preference represents the default log level for the Bluetooth stack
|
||||
*
|
||||
* The default log level is captured and held in an Android Log Framework log tag, using "bluetooth"
|
||||
* as the tag name. The Log framework does not provide methods to directly write a log tag value,
|
||||
* but instead leverages special system properties to hold the value of a log tag.
|
||||
*
|
||||
* This preferences aims to keep the selection in sync with the currently set log tag value. It
|
||||
* writes directly to the system properties that hold the level associated with the bluetooth log
|
||||
* tag. It leverages the Log.isLoggable("bluetooth", level) function to discern the current value.
|
||||
* The default level is INFO.
|
||||
*
|
||||
* This value is read once at start of the Bluetooth stack. To use a new value once setting it, be
|
||||
* sure to turn Bluetooth off and back on again.
|
||||
*/
|
||||
public class BluetoothStackLogPreferenceController extends DeveloperOptionsPreferenceController
|
||||
implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
|
||||
private static final String TAG = BluetoothStackLogPreferenceController.class.getSimpleName();
|
||||
|
||||
private static final String PREFERENCE_KEY = "bt_stack_log_level";
|
||||
|
||||
/* Ensure that the indexes match with bt_stack_log_values and bt_stack_log_entries ordering */
|
||||
private static final String PREFERENCE_KEY = "bt_stack_log_level";
|
||||
@VisibleForTesting static final int BTSTACK_LOG_MODE_VERBOSE_INDEX = 0;
|
||||
@VisibleForTesting static final int BTSTACK_LOG_MODE_DEBUG_INDEX = 1;
|
||||
@VisibleForTesting static final int BTSTACK_LOG_MODE_INFO_INDEX = 2;
|
||||
@VisibleForTesting static final int BTSTACK_LOG_MODE_WARN_INDEX = 3;
|
||||
@VisibleForTesting static final int BTSTACK_LOG_MODE_ERROR_INDEX = 4;
|
||||
private static final int BT_LOG_LEVEL_VERBOSE_INDEX = 0;
|
||||
private static final int BT_LOG_LEVEL_DEBUG_INDEX = 1;
|
||||
private static final int BT_LOG_LEVEL_INFO_INDEX = 2;
|
||||
private static final int BT_LOG_LEVEL_WARN_INDEX = 3;
|
||||
private static final int BT_LOG_LEVEL_ERROR_INDEX = 4;
|
||||
@VisibleForTesting static final int BT_LOG_LEVEL_DEFAULT_INDEX = BT_LOG_LEVEL_INFO_INDEX;
|
||||
|
||||
@VisibleForTesting
|
||||
static final String BLUETOOTH_BTSTACK_LOG_MODE_PROPERTY_PERSIST = "persist.log.tag.bluetooth";
|
||||
static final String BLUETOOTH_BTSTACK_LOG_MODE_PROPERTY = "log.tag.bluetooth";
|
||||
static final String BLUETOOTH_STRING_NAME = "bluetooth";
|
||||
static final int DEFAULT_MODE = BTSTACK_LOG_MODE_INFO_INDEX;
|
||||
|
||||
private final String[] mListValues;
|
||||
private final String[] mListEntries;
|
||||
private static final String BT_LOG_TAG = "bluetooth";
|
||||
@VisibleForTesting static final String BT_LOG_LEVEL_PROP_PERSIST = "persist.log.tag.bluetooth";
|
||||
@VisibleForTesting static final String BT_LOG_LEVEL_PROP = "log.tag.bluetooth";
|
||||
|
||||
// Values represents the untranslatable log level strings that should be used for writing to
|
||||
// system properties. Entries represents the translatable log level strings that should be used
|
||||
// in the UI to communicate to the user their options for this preference.
|
||||
private String[] mListValues;
|
||||
private String[] mListEntries;
|
||||
|
||||
/**
|
||||
* Create a BluetoothStackLogPreferenceController instance
|
||||
*/
|
||||
public BluetoothStackLogPreferenceController(@NonNull Context context) {
|
||||
super(context);
|
||||
mListValues = context.getResources().getStringArray(R.array.bt_stack_log_level_values);
|
||||
mListEntries = context.getResources().getStringArray(R.array.bt_stack_log_level_entries);
|
||||
}
|
||||
|
||||
/** returns default log level index of INFO */
|
||||
public int getDefaultModeIndex() {
|
||||
return DEFAULT_MODE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the preference key associated with this preference
|
||||
*
|
||||
* Note that this key is _usually_ a system property in and of itself, which is expected to hold
|
||||
* the value of the preference. In this case though, this key *does not* hold the preference. It
|
||||
* is only really used to tie this controller to the list preference defined in the XML file.
|
||||
*
|
||||
* @return the preference key associated with this preference
|
||||
*/
|
||||
@Override
|
||||
@Nullable
|
||||
public String getPreferenceKey() {
|
||||
return PREFERENCE_KEY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the state of the preference based on what the user has selected
|
||||
*
|
||||
* This function is invoked when the user has selected a new value for this preference. The new
|
||||
* value is the entry value at the index of the list the user has selected. This value will be
|
||||
* one of the values from the array returned in getEntryValues(). Specifically, this array is
|
||||
* set using R.array.bt_stack_log_level_values
|
||||
*
|
||||
* @param preference - the preference object to set the value of
|
||||
* @param newValue - the value the user has selected, as an Object
|
||||
* @return True when updated successfully
|
||||
*/
|
||||
@Override
|
||||
public boolean onPreferenceChange(@NonNull Preference preference, @NonNull Object newValue) {
|
||||
SystemProperties.set(BLUETOOTH_BTSTACK_LOG_MODE_PROPERTY_PERSIST, newValue.toString());
|
||||
SystemProperties.set(BLUETOOTH_BTSTACK_LOG_MODE_PROPERTY, newValue.toString());
|
||||
updateState(mPreference);
|
||||
Log.v(TAG, "onPreferenceChange(pref=" + preference + "value=" + newValue.toString() + ")");
|
||||
setBluetoothLogTag(newValue.toString());
|
||||
setBluetoothLogLevelIndex(getBluetoothLogLevelIndex());
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the state of this preference based on the state stored on the system
|
||||
*
|
||||
* Read the Bluetooth stack log level from the underlying system property/log tag, and map that
|
||||
* level to the proper index in the values and entries array. Use those strings to set the value
|
||||
* and summary of the preference.
|
||||
*
|
||||
* @param preference - the preference object to refresh the state of
|
||||
*/
|
||||
@Override
|
||||
public void updateState(@NonNull Preference preference) {
|
||||
final ListPreference listPreference = (ListPreference) preference;
|
||||
int index = getBluetoothLogLevelIndex();
|
||||
listPreference.setValue(mListValues[index]);
|
||||
listPreference.setSummary(mListEntries[index]);
|
||||
Log.v(TAG, "updateState(pref=" + preference + "): refresh preference state");
|
||||
setBluetoothLogLevelIndex(getBluetoothLogLevelIndex());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current log level from Log.isLoggable().
|
||||
* Notify this developer options preference of a change to developer options visibility
|
||||
*
|
||||
* We developer options are closed, we should clear out the value of this developer option
|
||||
* preference and revert it back to the default state of INFO.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public int getBluetoothLogLevelIndex() {
|
||||
if (Log.isLoggable(BLUETOOTH_STRING_NAME, Log.VERBOSE)) {
|
||||
return BTSTACK_LOG_MODE_VERBOSE_INDEX;
|
||||
} else if (Log.isLoggable(BLUETOOTH_STRING_NAME, Log.DEBUG)) {
|
||||
return BTSTACK_LOG_MODE_DEBUG_INDEX;
|
||||
} else if (Log.isLoggable(BLUETOOTH_STRING_NAME, Log.INFO)) {
|
||||
return BTSTACK_LOG_MODE_INFO_INDEX;
|
||||
} else if (Log.isLoggable(BLUETOOTH_STRING_NAME, Log.WARN)) {
|
||||
return BTSTACK_LOG_MODE_WARN_INDEX;
|
||||
} else if (Log.isLoggable(BLUETOOTH_STRING_NAME, Log.ERROR)) {
|
||||
return BTSTACK_LOG_MODE_ERROR_INDEX;
|
||||
}
|
||||
return BTSTACK_LOG_MODE_INFO_INDEX;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDeveloperOptionsSwitchDisabled() {
|
||||
super.onDeveloperOptionsSwitchDisabled();
|
||||
SystemProperties.set(BLUETOOTH_BTSTACK_LOG_MODE_PROPERTY_PERSIST, null);
|
||||
SystemProperties.set(BLUETOOTH_BTSTACK_LOG_MODE_PROPERTY, null);
|
||||
((ListPreference) mPreference).setValue(mListValues[getDefaultModeIndex()]);
|
||||
((ListPreference) mPreference).setSummary(mListEntries[getDefaultModeIndex()]);
|
||||
Log.v(TAG, "onDeveloperOptionsSwitchDisabled(): Revert stack log to default");
|
||||
setBluetoothLogTag(null);
|
||||
setBluetoothLogLevelIndex(BT_LOG_LEVEL_DEFAULT_INDEX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the system property values used by the Log framework to read the "bluetooth" log tag
|
||||
*
|
||||
* @param logLevel - the log level to set the Bluetooth stack minimum log level to
|
||||
*/
|
||||
private void setBluetoothLogTag(@Nullable String logLevel) {
|
||||
Log.i(TAG, "setBluetoothLogTag(logLevel=" + logLevel + "): Set properties for log tag");
|
||||
SystemProperties.set(BT_LOG_LEVEL_PROP_PERSIST, logLevel);
|
||||
SystemProperties.set(BT_LOG_LEVEL_PROP, logLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry and value index corresponding to the current Bluetooth stack log level
|
||||
*
|
||||
* Since this preference uses an actual log tag and not a specific/private system property, we
|
||||
* can read the value using the Log.isLoggable() function with our "bluetooth" log tag that
|
||||
* represents the log level of the Bluetooth stack. This is safer than trying to replacate the
|
||||
* logic used in the Log framework around the various persist, ro, and blank variants of the tag
|
||||
*
|
||||
* If no value is present, INFO is used.
|
||||
*
|
||||
* @return the entry/value index corresponding to the current log level of the tag "bluetooth"
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public int getBluetoothLogLevelIndex() {
|
||||
int level = BT_LOG_LEVEL_DEFAULT_INDEX;
|
||||
if (Log.isLoggable(BT_LOG_TAG, Log.VERBOSE)) {
|
||||
level = BT_LOG_LEVEL_VERBOSE_INDEX;
|
||||
} else if (Log.isLoggable(BT_LOG_TAG, Log.DEBUG)) {
|
||||
level = BT_LOG_LEVEL_DEBUG_INDEX;
|
||||
} else if (Log.isLoggable(BT_LOG_TAG, Log.INFO)) {
|
||||
level = BT_LOG_LEVEL_INFO_INDEX;
|
||||
} else if (Log.isLoggable(BT_LOG_TAG, Log.WARN)) {
|
||||
level = BT_LOG_LEVEL_WARN_INDEX;
|
||||
} else if (Log.isLoggable(BT_LOG_TAG, Log.ERROR)) {
|
||||
level = BT_LOG_LEVEL_ERROR_INDEX;
|
||||
}
|
||||
Log.v(TAG, "getBluetoothLogLevelIndex() -> " + level);
|
||||
return level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current Bluetooth stack log level displayed in the list for this preference
|
||||
*
|
||||
* @param index - the index representing the log level choice of this preference
|
||||
*/
|
||||
private void setBluetoothLogLevelIndex(int index) {
|
||||
if (index < BT_LOG_LEVEL_VERBOSE_INDEX || index > BT_LOG_LEVEL_ERROR_INDEX) {
|
||||
Log.e(TAG, "setBluetoothLogLevelIndex(index=" + index + "): Log level invalid");
|
||||
return;
|
||||
}
|
||||
|
||||
String value = mListValues[index];
|
||||
String entryValue = mListEntries[index];
|
||||
|
||||
ListPreference preference = ((ListPreference) mPreference);
|
||||
if (preference == null) {
|
||||
Log.e(TAG, "setBluetoothLogLevelIndex(index=" + index + "): mPreference is null");
|
||||
return;
|
||||
}
|
||||
|
||||
preference.setValue(value);
|
||||
preference.setSummary(entryValue);
|
||||
|
||||
Log.i(TAG, "setBluetoothLogLevelIndex(index=" + index
|
||||
+ "): Updated Bluetooth stack log level to value='" + value + "', entryValue='"
|
||||
+ entryValue + "'");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user