diff --git a/res/values/strings.xml b/res/values/strings.xml index f695be50ebf..5d4cb63ad6c 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -3064,9 +3064,9 @@ Storage settings - EID + E​ID - EID (sim slot %1$d) + E​ID (sim slot %1$d) IMEI (sim slot %1$d) diff --git a/res/xml/power_usage_summary.xml b/res/xml/power_usage_summary.xml index 1af8a8c2410..77c6b7322c2 100644 --- a/res/xml/power_usage_summary.xml +++ b/res/xml/power_usage_summary.xml @@ -33,7 +33,7 @@ android:selectable="false" settings:searchable="false" /> - diff --git a/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragment.java b/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragment.java index 87b2c6b65d0..e0171439198 100644 --- a/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragment.java +++ b/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragment.java @@ -19,7 +19,9 @@ package com.android.settings.bluetooth; import static android.bluetooth.BluetoothDevice.BOND_NONE; import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH; +import android.app.Activity; import android.app.settings.SettingsEnums; +import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.content.Context; import android.content.Intent; @@ -51,6 +53,7 @@ import com.android.settings.dashboard.RestrictedDashboardFragment; import com.android.settings.inputmethod.KeyboardSettingsPreferenceController; import com.android.settings.overlay.FeatureFactory; import com.android.settings.slices.SlicePreferenceController; +import com.android.settingslib.bluetooth.BluetoothCallback; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.core.AbstractPreferenceController; @@ -98,6 +101,20 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment private UserManager mUserManager; + private final BluetoothCallback mBluetoothCallback = + new BluetoothCallback() { + @Override + public void onBluetoothStateChanged(int bluetoothState) { + if (bluetoothState == BluetoothAdapter.STATE_OFF) { + Log.i(TAG, "Bluetooth is off, exit activity."); + Activity activity = getActivity(); + if (activity != null) { + activity.finish(); + } + } + } + }; + public BluetoothDeviceDetailsFragment() { super(DISALLOW_CONFIG_BLUETOOTH); } @@ -183,6 +200,14 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment use(BlockingPrefWithSliceController.class).setSliceUri(sliceEnabled ? featureProvider.getBluetoothDeviceSettingsUri(mCachedDevice.getDevice()) : null); + + mManager.getEventManager().registerCallback(mBluetoothCallback); + } + + @Override + public void onDetach() { + super.onDetach(); + mManager.getEventManager().unregisterCallback(mBluetoothCallback); } private void updateExtraControlUri(int viewWidth) { diff --git a/src/com/android/settings/fuelgauge/batterytip/BatteryTipPreferenceController.java b/src/com/android/settings/fuelgauge/batterytip/BatteryTipPreferenceController.java index 31cec6a46ba..e6f622cf00b 100644 --- a/src/com/android/settings/fuelgauge/batterytip/BatteryTipPreferenceController.java +++ b/src/com/android/settings/fuelgauge/batterytip/BatteryTipPreferenceController.java @@ -33,7 +33,7 @@ import com.android.settings.core.InstrumentedPreferenceFragment; import com.android.settings.fuelgauge.batterytip.actions.BatteryTipAction; import com.android.settings.fuelgauge.batterytip.tips.BatteryTip; import com.android.settings.overlay.FeatureFactory; -import com.android.settings.widget.CardPreference; +import com.android.settings.widget.TipCardPreference; import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; import java.util.List; @@ -55,7 +55,7 @@ public class BatteryTipPreferenceController extends BasePreferenceController { private SettingsActivity mSettingsActivity; private MetricsFeatureProvider mMetricsFeatureProvider; private boolean mNeedUpdate; - @VisibleForTesting CardPreference mCardPreference; + @VisibleForTesting TipCardPreference mCardPreference; @VisibleForTesting Context mPrefContext; InstrumentedPreferenceFragment mFragment; diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/BatteryDefenderTip.java b/src/com/android/settings/fuelgauge/batterytip/tips/BatteryDefenderTip.java index 37162448b1b..dbe2722ebea 100644 --- a/src/com/android/settings/fuelgauge/batterytip/tips/BatteryDefenderTip.java +++ b/src/com/android/settings/fuelgauge/batterytip/tips/BatteryDefenderTip.java @@ -28,7 +28,6 @@ import androidx.preference.Preference; import com.android.settings.R; import com.android.settings.overlay.FeatureFactory; -import com.android.settings.widget.CardPreference; import com.android.settingslib.HelpUtils; import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; @@ -80,9 +79,9 @@ public class BatteryDefenderTip extends BatteryTip { super.updatePreference(preference); final Context context = preference.getContext(); - CardPreference cardPreference = castToCardPreferenceSafely(preference); + var cardPreference = castToTipCardPreferenceSafely(preference); if (cardPreference == null) { - Log.e(TAG, "cast Preference to CardPreference failed"); + Log.e(TAG, "cast Preference to TipCardPreference failed"); return; } diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTip.java b/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTip.java index 1345032d2ae..1f5374dac8a 100644 --- a/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTip.java +++ b/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTip.java @@ -23,10 +23,11 @@ import android.util.SparseIntArray; import androidx.annotation.DrawableRes; import androidx.annotation.IntDef; +import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; import androidx.preference.Preference; -import com.android.settings.widget.CardPreference; +import com.android.settings.widget.TipCardPreference; import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; import java.lang.annotation.Retention; @@ -165,7 +166,7 @@ public abstract class BatteryTip implements Comparable, Parcelable { preference.setTitle(getTitle(context)); preference.setSummary(getSummary(context)); preference.setIcon(getIconId()); - final CardPreference cardPreference = castToCardPreferenceSafely(preference); + final TipCardPreference cardPreference = castToTipCardPreferenceSafely(preference); if (cardPreference != null) { cardPreference.resetLayoutState(); } @@ -206,7 +207,9 @@ public abstract class BatteryTip implements Comparable, Parcelable { return "type=" + mType + " state=" + mState; } - public CardPreference castToCardPreferenceSafely(Preference preference) { - return preference instanceof CardPreference ? (CardPreference) preference : null; + /** Returns the converted {@link TipCardPreference} if it is valid. */ + @Nullable + public TipCardPreference castToTipCardPreferenceSafely(Preference preference) { + return preference instanceof TipCardPreference ? (TipCardPreference) preference : null; } } diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/IncompatibleChargerTip.java b/src/com/android/settings/fuelgauge/batterytip/tips/IncompatibleChargerTip.java index 72c710c023f..7453dedf41c 100644 --- a/src/com/android/settings/fuelgauge/batterytip/tips/IncompatibleChargerTip.java +++ b/src/com/android/settings/fuelgauge/batterytip/tips/IncompatibleChargerTip.java @@ -26,7 +26,6 @@ import androidx.core.app.ActivityCompat; import androidx.preference.Preference; import com.android.settings.R; -import com.android.settings.widget.CardPreference; import com.android.settingslib.HelpUtils; import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; @@ -74,7 +73,7 @@ public final class IncompatibleChargerTip extends BatteryTip { public void updatePreference(Preference preference) { super.updatePreference(preference); final Context context = preference.getContext(); - final CardPreference cardPreference = castToCardPreferenceSafely(preference); + final var cardPreference = castToTipCardPreferenceSafely(preference); if (cardPreference == null) { Log.e(TAG, "cast Preference to CardPreference failed"); return; diff --git a/src/com/android/settings/fuelgauge/batteryusage/AnomalyEventWrapper.java b/src/com/android/settings/fuelgauge/batteryusage/AnomalyEventWrapper.java index 8924a0b15e3..be5de06e582 100644 --- a/src/com/android/settings/fuelgauge/batteryusage/AnomalyEventWrapper.java +++ b/src/com/android/settings/fuelgauge/batteryusage/AnomalyEventWrapper.java @@ -18,9 +18,13 @@ package com.android.settings.fuelgauge.batteryusage; import android.content.Context; import android.os.Bundle; +import android.provider.Settings; import android.text.TextUtils; +import android.util.Log; import android.util.Pair; +import androidx.annotation.Nullable; + import com.android.settings.R; import com.android.settings.SettingsActivity; import com.android.settings.core.SubSettingLauncher; @@ -49,8 +53,8 @@ final class AnomalyEventWrapper { } private T getInfo( - Function warningBannerInfoSupplier, - Function warningItemInfoSupplier) { + @Nullable Function warningBannerInfoSupplier, + @Nullable Function warningItemInfoSupplier) { if (warningBannerInfoSupplier != null && mPowerAnomalyEvent.hasWarningBannerInfo()) { return warningBannerInfoSupplier.apply(mPowerAnomalyEvent.getWarningBannerInfo()); } else if (warningItemInfoSupplier != null && mPowerAnomalyEvent.hasWarningItemInfo()) { @@ -252,4 +256,32 @@ final class AnomalyEventWrapper { mSubSettingLauncher.launch(); return true; } + + boolean updateSystemSettingsIfAvailable() { + final String settingsName = + getInfo(WarningBannerInfo::getMainButtonConfigSettingsName, null); + final Integer settingsValue = + getInfo(WarningBannerInfo::getMainButtonConfigSettingsValue, null); + if (TextUtils.isEmpty(settingsName) || settingsValue == null) { + Log.d(TAG, "Failed to update settings due to invalid key or value"); + return false; + } + + try { + Settings.System.putInt(mContext.getContentResolver(), settingsName, settingsValue); + Log.d( + TAG, + String.format( + "Update settings name=%s to value=%d", settingsName, settingsValue)); + return true; + } catch (SecurityException e) { + Log.w( + TAG, + String.format( + "Failed to update settings name=%s to value=%d", + settingsName, settingsValue), + e); + return false; + } + } } diff --git a/src/com/android/settings/fuelgauge/batteryusage/BatteryTipsController.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryTipsController.java index e22f987c12e..821c8680522 100644 --- a/src/com/android/settings/fuelgauge/batteryusage/BatteryTipsController.java +++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryTipsController.java @@ -123,7 +123,8 @@ public class BatteryTipsController extends BasePreferenceController { mCardPreference.setVisible(false); if (mOnAnomalyConfirmListener != null) { mOnAnomalyConfirmListener.onAnomalyConfirm(); - } else if (mAnomalyEventWrapper.launchSubSetting()) { + } else if (mAnomalyEventWrapper.updateSystemSettingsIfAvailable() + || mAnomalyEventWrapper.launchSubSetting()) { mMetricsFeatureProvider.action( /* attribution= */ SettingsEnums.FUELGAUGE_BATTERY_HISTORY_DETAIL, /* action= */ SettingsEnums.ACTION_BATTERY_TIPS_CARD_ACCEPT, diff --git a/src/com/android/settings/fuelgauge/protos/power_anomaly_event.proto b/src/com/android/settings/fuelgauge/protos/power_anomaly_event.proto index 3c0705fff24..ef0a9e09f03 100644 --- a/src/com/android/settings/fuelgauge/protos/power_anomaly_event.proto +++ b/src/com/android/settings/fuelgauge/protos/power_anomaly_event.proto @@ -57,6 +57,8 @@ message WarningBannerInfo { // Used in the SubSettingLauncher.setArguments(). optional string main_button_source_highlight_key = 6; optional string cancel_button_string = 7; + optional string main_button_config_settings_name = 8; + optional int32 main_button_config_settings_value = 9; } message WarningItemInfo { diff --git a/src/com/android/settings/network/SimOnboardingService.kt b/src/com/android/settings/network/SimOnboardingService.kt index a82125527a8..b99f18d9667 100644 --- a/src/com/android/settings/network/SimOnboardingService.kt +++ b/src/com/android/settings/network/SimOnboardingService.kt @@ -225,7 +225,7 @@ class SimOnboardingService { } fun addItemForRenaming(subInfo: SubscriptionInfo, newName: String) { - if (newName.isEmpty() && subInfo.displayName == newName) { + if (subInfo.displayName == newName) { return } renameMutableMap[subInfo.subscriptionId] = newName diff --git a/src/com/android/settings/privatespace/PrivateSpaceMaintainer.java b/src/com/android/settings/privatespace/PrivateSpaceMaintainer.java index 6d07305e375..3a084102ec5 100644 --- a/src/com/android/settings/privatespace/PrivateSpaceMaintainer.java +++ b/src/com/android/settings/privatespace/PrivateSpaceMaintainer.java @@ -20,6 +20,7 @@ import static android.os.UserManager.USER_TYPE_PROFILE_PRIVATE; import static android.provider.Settings.Secure.HIDE_PRIVATESPACE_ENTRY_POINT; import static android.provider.Settings.Secure.PRIVATE_SPACE_AUTO_LOCK; import static android.provider.Settings.Secure.PRIVATE_SPACE_AUTO_LOCK_AFTER_DEVICE_RESTART; +import static android.provider.Settings.Secure.SKIP_FIRST_USE_HINTS; import static android.provider.Settings.Secure.USER_SETUP_COMPLETE; import android.app.ActivityManager; @@ -122,6 +123,7 @@ public class PrivateSpaceMaintainer { Log.i(TAG, "Private space created with id: " + mUserHandle.getIdentifier()); resetPrivateSpaceSettings(); setUserSetupComplete(); + setSkipFirstUseHints(); } return true; } @@ -350,6 +352,17 @@ public class PrivateSpaceMaintainer { 1, mUserHandle.getIdentifier()); } + /** + * Sets the SKIP_FIRST_USE_HINTS for private profile so that the first launch of an app in + * private space will not display introductory hints. + */ + @GuardedBy("this") + private void setSkipFirstUseHints() { + Log.d(TAG, "setting SKIP_FIRST_USE_HINTS = 1 for private profile"); + Settings.Secure.putIntForUser(mContext.getContentResolver(), SKIP_FIRST_USE_HINTS, + 1, mUserHandle.getIdentifier()); + } + private boolean isPrivateSpaceAutoLockSupported() { return android.os.Flags.allowPrivateProfile() && android.multiuser.Flags.supportAutolockForPrivateSpace() diff --git a/src/com/android/settings/widget/CardPreference.java b/src/com/android/settings/widget/CardPreference.java new file mode 100644 index 00000000000..db6827efab8 --- /dev/null +++ b/src/com/android/settings/widget/CardPreference.java @@ -0,0 +1,164 @@ +/* + * Copyright (C) 2019 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.widget; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.View; +import android.widget.Button; + +import androidx.annotation.Nullable; +import androidx.preference.Preference; +import androidx.preference.PreferenceViewHolder; + +import com.android.settings.R; + +import com.google.android.material.card.MaterialCardView; + +import java.util.Optional; + +/** Preference that wrapped by {@link MaterialCardView} */ +public class CardPreference extends Preference { + @Nullable private View.OnClickListener mPrimaryBtnClickListener = null; + @Nullable private View.OnClickListener mSecondaryBtnClickListener = null; + @Nullable private String mPrimaryButtonText = null; + @Nullable private String mSecondaryButtonText = null; + private Optional