controllers = new ArrayList<>();
+ if (!isSimHardwareVisible(context)) {
+ return controllers;
+ }
mSummaryController =
new DataUsageSummaryPreferenceController(activity, getSettingsLifecycle(), this,
DataUsageUtils.getDefaultSubscriptionId(activity));
diff --git a/src/com/android/settings/datetime/timezone/BaseTimeZonePicker.java b/src/com/android/settings/datetime/timezone/BaseTimeZonePicker.java
index 6ce9f6f9ae8527a1c62ebba79c8b811e529f5e00..abdfc881b897f0edb470ae7495447a1dd0441891 100644
--- a/src/com/android/settings/datetime/timezone/BaseTimeZonePicker.java
+++ b/src/com/android/settings/datetime/timezone/BaseTimeZonePicker.java
@@ -136,6 +136,7 @@ public abstract class BaseTimeZonePicker extends InstrumentedFragment
mSearchView.setQueryHint(getText(mSearchHintResId));
mSearchView.setOnQueryTextListener(this);
+ mSearchView.setMaxWidth(Integer.MAX_VALUE);
if (mDefaultExpandSearch) {
searchMenuItem.expandActionView();
diff --git a/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceController.java b/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceController.java
index bd8169a80fe3eeb340ab05f168bc789c99f73807..a1467c80ac53b29881b2aeef15ab2923c84a4aa5 100644
--- a/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceController.java
+++ b/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceController.java
@@ -16,9 +16,8 @@
package com.android.settings.development;
+import android.bluetooth.BluetoothManager;
import android.content.Context;
-import android.content.pm.PackageManager;
-import android.content.res.Resources;
import android.os.SystemProperties;
import androidx.annotation.VisibleForTesting;
@@ -45,15 +44,10 @@ public class BluetoothMaxConnectedAudioDevicesPreferenceController extends
public BluetoothMaxConnectedAudioDevicesPreferenceController(Context context) {
super(context);
- try {
- Resources res = context.getPackageManager().getResourcesForApplication(
- "com.android.bluetooth");
- mDefaultMaxConnectedAudioDevices = res.getInteger(res.getIdentifier(
- "config_bluetooth_max_connected_audio_devices",
- "integer", "com.android.bluetooth"));
- } catch (PackageManager.NameNotFoundException e) {
- e.printStackTrace();
- }
+ final BluetoothManager bluetoothManager = context.getSystemService(BluetoothManager.class);
+
+ mDefaultMaxConnectedAudioDevices =
+ bluetoothManager.getAdapter().getMaxConnectedAudioDevices();
}
@Override
diff --git a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
index d92fb7fd99b5aab6b8745dbbc49b818ca5f8f41d..70fbefc36f4b4b7f850d09ca13ed1f8365327644 100644
--- a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
+++ b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
@@ -60,6 +60,7 @@ import com.android.settings.development.bluetooth.BluetoothQualityDialogPreferen
import com.android.settings.development.bluetooth.BluetoothSampleRateDialogPreferenceController;
import com.android.settings.development.qstile.DevelopmentTiles;
import com.android.settings.development.storage.SharedDataPreferenceController;
+import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.actionbar.SearchMenuController;
import com.android.settings.widget.SettingsMainSwitchBar;
@@ -308,6 +309,8 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
DisableDevSettingsDialogFragment.show(this /* host */);
}
}
+ FeatureFactory.getFactory(
+ getContext()).getSearchFeatureProvider().sendPreIndexIntent(getContext());
}
}
@@ -369,12 +372,12 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
final BluetoothLeAudioHwOffloadPreferenceController leAudioController =
getDevelopmentOptionsController(
- BluetoothLeAudioHwOffloadPreferenceController.class);
+ BluetoothLeAudioHwOffloadPreferenceController.class);
leAudioController.onRebootDialogConfirmed();
final BluetoothLeAudioPreferenceController leAudioFeatureController =
getDevelopmentOptionsController(
- BluetoothLeAudioPreferenceController.class);
+ BluetoothLeAudioPreferenceController.class);
leAudioFeatureController.onRebootDialogConfirmed();
}
@@ -386,12 +389,12 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
final BluetoothLeAudioHwOffloadPreferenceController leAudioController =
getDevelopmentOptionsController(
- BluetoothLeAudioHwOffloadPreferenceController.class);
+ BluetoothLeAudioHwOffloadPreferenceController.class);
leAudioController.onRebootDialogCanceled();
final BluetoothLeAudioPreferenceController leAudioFeatureController =
getDevelopmentOptionsController(
- BluetoothLeAudioPreferenceController.class);
+ BluetoothLeAudioPreferenceController.class);
leAudioFeatureController.onRebootDialogCanceled();
}
diff --git a/src/com/android/settings/development/transcode/TranscodeDefaultOptionPreferenceController.java b/src/com/android/settings/development/transcode/TranscodeDefaultOptionPreferenceController.java
index 1c2fcd984102a3c1a9b43b302e71f2fd60fc9954..a12aa642d7e1039d76c43dcb436b13a19b1f3a44 100644
--- a/src/com/android/settings/development/transcode/TranscodeDefaultOptionPreferenceController.java
+++ b/src/com/android/settings/development/transcode/TranscodeDefaultOptionPreferenceController.java
@@ -21,6 +21,7 @@ import android.os.SystemProperties;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
+import com.android.settingslib.development.DevelopmentSettingsEnabler;
/**
* The controller (on the transcode settings screen) indicating that by default we assume that apps
@@ -47,7 +48,11 @@ public class TranscodeDefaultOptionPreferenceController extends TogglePreference
@Override
public int getAvailabilityStatus() {
- return AVAILABLE;
+ if (DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(mContext)) {
+ return AVAILABLE;
+ } else {
+ return CONDITIONALLY_UNAVAILABLE;
+ }
}
@Override
diff --git a/src/com/android/settings/development/transcode/TranscodeDisableCachePreferenceController.java b/src/com/android/settings/development/transcode/TranscodeDisableCachePreferenceController.java
index c3b0624e9dfa05829062843377254facfc421309..8229c98bfa286e6b5cd00ac91b8bfd70523be0cb 100644
--- a/src/com/android/settings/development/transcode/TranscodeDisableCachePreferenceController.java
+++ b/src/com/android/settings/development/transcode/TranscodeDisableCachePreferenceController.java
@@ -22,6 +22,7 @@ import android.os.SystemProperties;
import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
+import com.android.settingslib.development.DevelopmentSettingsEnabler;
/**
* The controller (in the Media transcoding settings) indicating the user's preference to disable
@@ -49,7 +50,11 @@ public class TranscodeDisableCachePreferenceController extends TogglePreferenceC
@Override
public int getAvailabilityStatus() {
- return AVAILABLE;
+ if (DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(mContext)) {
+ return AVAILABLE;
+ } else {
+ return CONDITIONALLY_UNAVAILABLE;
+ }
}
@Override
diff --git a/src/com/android/settings/development/transcode/TranscodeGlobalTogglePreferenceController.java b/src/com/android/settings/development/transcode/TranscodeGlobalTogglePreferenceController.java
index b2d446e0721eb83991e238a4753ecca0e565e7a3..63572f711fd17b5dcd89fe0bf37b07e2b70e2479 100644
--- a/src/com/android/settings/development/transcode/TranscodeGlobalTogglePreferenceController.java
+++ b/src/com/android/settings/development/transcode/TranscodeGlobalTogglePreferenceController.java
@@ -21,6 +21,7 @@ import android.os.SystemProperties;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
+import com.android.settingslib.development.DevelopmentSettingsEnabler;
/**
* The controller for the "Enabling transcoding for all apps" switch on the transcode settings
@@ -37,7 +38,11 @@ public class TranscodeGlobalTogglePreferenceController extends TogglePreferenceC
@Override
public int getAvailabilityStatus() {
- return AVAILABLE;
+ if (DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(mContext)) {
+ return AVAILABLE;
+ } else {
+ return CONDITIONALLY_UNAVAILABLE;
+ }
}
@Override
diff --git a/src/com/android/settings/development/transcode/TranscodeNotificationPreferenceController.java b/src/com/android/settings/development/transcode/TranscodeNotificationPreferenceController.java
index 6b6692e5811de2688bb07d51d8dd34b2fb4ad3f9..11c9c7432793fb84d4595cec6579fa65e3cb9f28 100644
--- a/src/com/android/settings/development/transcode/TranscodeNotificationPreferenceController.java
+++ b/src/com/android/settings/development/transcode/TranscodeNotificationPreferenceController.java
@@ -22,6 +22,7 @@ import android.os.SystemProperties;
import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
+import com.android.settingslib.development.DevelopmentSettingsEnabler;
/**
* The controller (in the Media transcoding settings) indicating the user's preference to show
@@ -49,7 +50,11 @@ public class TranscodeNotificationPreferenceController extends TogglePreferenceC
@Override
public int getAvailabilityStatus() {
- return AVAILABLE;
+ if (DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(mContext)) {
+ return AVAILABLE;
+ } else {
+ return CONDITIONALLY_UNAVAILABLE;
+ }
}
@Override
diff --git a/src/com/android/settings/development/transcode/TranscodeUserControlPreferenceController.java b/src/com/android/settings/development/transcode/TranscodeUserControlPreferenceController.java
index ce82293486c9bfc075aeb937b7a522dcbd3cccd2..377ff26dda3bf8b614fa2ecc5bfab2e88c9464d2 100644
--- a/src/com/android/settings/development/transcode/TranscodeUserControlPreferenceController.java
+++ b/src/com/android/settings/development/transcode/TranscodeUserControlPreferenceController.java
@@ -21,6 +21,7 @@ import android.os.SystemProperties;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
+import com.android.settingslib.development.DevelopmentSettingsEnabler;
/**
* The controller for the User's control (over other transcoding preferences) preference switch on
@@ -47,7 +48,11 @@ public class TranscodeUserControlPreferenceController extends TogglePreferenceCo
@Override
public int getAvailabilityStatus() {
- return AVAILABLE;
+ if (DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(mContext)) {
+ return AVAILABLE;
+ } else {
+ return CONDITIONALLY_UNAVAILABLE;
+ }
}
@Override
diff --git a/src/com/android/settings/deviceinfo/BuildNumberPreferenceController.java b/src/com/android/settings/deviceinfo/BuildNumberPreferenceController.java
index 7ddca793f597abe75712fbf1e69cabde07a28a2c..6af58b5bc6b4cb272148506197771a61dff2cc58 100644
--- a/src/com/android/settings/deviceinfo/BuildNumberPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/BuildNumberPreferenceController.java
@@ -240,6 +240,8 @@ public class BuildNumberPreferenceController extends BasePreferenceController im
mDevHitToast = Toast.makeText(mContext, R.string.show_dev_on,
Toast.LENGTH_LONG);
mDevHitToast.show();
+
+ FeatureFactory.getFactory(mContext).getSearchFeatureProvider().sendPreIndexIntent(mContext);
}
@VisibleForTesting
diff --git a/src/com/android/settings/deviceinfo/PhoneNumberPreferenceController.java b/src/com/android/settings/deviceinfo/PhoneNumberPreferenceController.java
index eb8add5dbe9990ce7926fcd4a009f93d5b44d804..f91b98f249ef51da3c6d88c73991cca850fcb1a3 100644
--- a/src/com/android/settings/deviceinfo/PhoneNumberPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/PhoneNumberPreferenceController.java
@@ -29,6 +29,7 @@ import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
+import com.android.settings.network.SubscriptionUtil;
import com.android.settingslib.DeviceInfoUtils;
import java.util.ArrayList;
@@ -51,7 +52,8 @@ public class PhoneNumberPreferenceController extends BasePreferenceController {
@Override
public int getAvailabilityStatus() {
- return mTelephonyManager.isVoiceCapable() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
+ return SubscriptionUtil.isSimHardwareVisible(mContext) ?
+ AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
@Override
@@ -79,6 +81,9 @@ public class PhoneNumberPreferenceController extends BasePreferenceController {
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
+ if (!SubscriptionUtil.isSimHardwareVisible(mContext)) {
+ return;
+ }
final Preference preference = screen.findPreference(getPreferenceKey());
final PreferenceCategory category = screen.findPreference(KEY_PREFERENCE_CATEGORY);
mPreferenceList.add(preference);
diff --git a/src/com/android/settings/deviceinfo/StorageWizardBase.java b/src/com/android/settings/deviceinfo/StorageWizardBase.java
index c39f384129952765a31362733a9add353cf4887e..7203d8a7702caa90431cd5f43d2ba14eb21956aa 100644
--- a/src/com/android/settings/deviceinfo/StorageWizardBase.java
+++ b/src/com/android/settings/deviceinfo/StorageWizardBase.java
@@ -46,6 +46,7 @@ import com.android.settings.SetupWizardUtils;
import com.google.android.setupcompat.template.FooterBarMixin;
import com.google.android.setupcompat.template.FooterButton;
import com.google.android.setupdesign.GlifLayout;
+import com.google.android.setupdesign.template.HeaderMixin;
import com.google.android.setupdesign.util.ThemeHelper;
import com.google.android.setupdesign.util.ThemeResolver;
@@ -167,7 +168,9 @@ public abstract class StorageWizardBase extends FragmentActivity {
protected void setHeaderText(int resId, CharSequence... args) {
final CharSequence headerText = TextUtils.expandTemplate(getText(resId), args);
- getGlifLayout().setHeaderText(headerText);
+ final GlifLayout layout = getGlifLayout();
+ layout.setHeaderText(headerText);
+ layout.getMixin(HeaderMixin.class).setAutoTextSizeEnabled(false);
setTitle(headerText);
}
diff --git a/src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceController.java b/src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceController.java
index e90477270e0ba734afec82db6e1c9fcd238e5a87..9b7359b0c8dd0bdcd33b10f96d2bc3d0beb66860 100644
--- a/src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceController.java
@@ -33,6 +33,7 @@ import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.deviceinfo.PhoneNumberSummaryPreference;
+import com.android.settings.network.SubscriptionUtil;
import com.android.settingslib.Utils;
import java.util.ArrayList;
@@ -63,6 +64,9 @@ public class ImeiInfoPreferenceController extends BasePreferenceController {
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
+ if (!SubscriptionUtil.isSimHardwareVisible(mContext)) {
+ return;
+ }
final Preference preference = screen.findPreference(getPreferenceKey());
final PreferenceCategory category = screen.findPreference(KEY_PREFERENCE_CATEGORY);
@@ -119,7 +123,8 @@ public class ImeiInfoPreferenceController extends BasePreferenceController {
@Override
public int getAvailabilityStatus() {
- return mContext.getSystemService(UserManager.class).isAdminUser()
+ return SubscriptionUtil.isSimHardwareVisible(mContext) &&
+ mContext.getSystemService(UserManager.class).isAdminUser()
&& !Utils.isWifiOnly(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
diff --git a/src/com/android/settings/deviceinfo/simstatus/SimStatusPreferenceController.java b/src/com/android/settings/deviceinfo/simstatus/SimStatusPreferenceController.java
index e392bd6cc908543d16049f8e2bde837befa8196a..f811d2a86d21f002165044f4787b45ac599b9e03 100644
--- a/src/com/android/settings/deviceinfo/simstatus/SimStatusPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/simstatus/SimStatusPreferenceController.java
@@ -29,6 +29,7 @@ import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settings.network.SubscriptionUtil;
import com.android.settingslib.deviceinfo.AbstractSimStatusImeiInfoPreferenceController;
import java.util.ArrayList;
@@ -59,9 +60,18 @@ public class SimStatusPreferenceController extends
return KEY_SIM_STATUS;
}
+ @Override
+ public boolean isAvailable() {
+ return SubscriptionUtil.isSimHardwareVisible(mContext) &&
+ super.isAvailable();
+ }
+
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
+ if (!SubscriptionUtil.isSimHardwareVisible(mContext)) {
+ return;
+ }
final Preference preference = screen.findPreference(getPreferenceKey());
if (!isAvailable() || preference == null || !preference.isVisible()) {
return;
diff --git a/src/com/android/settings/display/ControlsPrivacyPreferenceController.java b/src/com/android/settings/display/ControlsPrivacyPreferenceController.java
index 6f146d5968b97572a071af0b52e07bb9c8da7c15..5b5b900800d3e5fcd4be1a6a6c66540e1a46eb46 100644
--- a/src/com/android/settings/display/ControlsPrivacyPreferenceController.java
+++ b/src/com/android/settings/display/ControlsPrivacyPreferenceController.java
@@ -62,6 +62,11 @@ public class ControlsPrivacyPreferenceController extends TogglePreferenceControl
@Override
public int getAvailabilityStatus() {
+ // hide if we should use customizable lock screen quick affordances
+ if (CustomizableLockScreenUtils.isFeatureEnabled(mContext)) {
+ return UNSUPPORTED_ON_DEVICE;
+ }
+
// hide if lockscreen isn't secure for this user
return isEnabled() && isSecure() ? AVAILABLE : DISABLED_DEPENDENT_SETTING;
}
diff --git a/src/com/android/settings/display/ControlsTrivialPrivacyPreferenceController.java b/src/com/android/settings/display/ControlsTrivialPrivacyPreferenceController.java
index 57f717b99137be765728e9daeee5a131140c0f05..be2de59b4b5063ee9e239c7387375813f4d2dd19 100644
--- a/src/com/android/settings/display/ControlsTrivialPrivacyPreferenceController.java
+++ b/src/com/android/settings/display/ControlsTrivialPrivacyPreferenceController.java
@@ -50,9 +50,11 @@ public class ControlsTrivialPrivacyPreferenceController extends TogglePreference
@Override
public CharSequence getSummary() {
- if (getAvailabilityStatus() == DISABLED_DEPENDENT_SETTING) {
+ if (!CustomizableLockScreenUtils.isFeatureEnabled(mContext)
+ && getAvailabilityStatus() == DISABLED_DEPENDENT_SETTING) {
return mContext.getText(R.string.lockscreen_trivial_disabled_controls_summary);
}
+
return mContext.getText(R.string.lockscreen_trivial_controls_summary);
}
@@ -74,13 +76,18 @@ public class ControlsTrivialPrivacyPreferenceController extends TogglePreference
}
private boolean showDeviceControlsSettingsEnabled() {
- return Settings.Secure.getInt(mContext.getContentResolver(), DEPENDENCY_SETTING_KEY, 0)
- != 0;
+ return CustomizableLockScreenUtils.isFeatureEnabled(mContext)
+ || Settings.Secure.getInt(
+ mContext.getContentResolver(), DEPENDENCY_SETTING_KEY, 0) != 0;
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
+ if (CustomizableLockScreenUtils.isFeatureEnabled(mContext)) {
+ return;
+ }
+
Preference currentPreference = screen.findPreference(getPreferenceKey());
currentPreference.setDependency("lockscreen_privacy_controls_switch");
}
diff --git a/src/com/android/settings/display/CustomizableLockScreenQuickAffordancesPreferenceController.java b/src/com/android/settings/display/CustomizableLockScreenQuickAffordancesPreferenceController.java
new file mode 100644
index 0000000000000000000000000000000000000000..2c06a51853c9d7a3bdfb2b6813aa4ee05de85031
--- /dev/null
+++ b/src/com/android/settings/display/CustomizableLockScreenQuickAffordancesPreferenceController.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2022 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.text.TextUtils;
+
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.core.PreferenceControllerMixin;
+
+/**
+ * Preference for accessing an experience to customize lock screen quick affordances.
+ */
+public class CustomizableLockScreenQuickAffordancesPreferenceController extends
+ BasePreferenceController implements PreferenceControllerMixin {
+
+ public CustomizableLockScreenQuickAffordancesPreferenceController(Context context, String key) {
+ super(context, key);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return CustomizableLockScreenUtils.isFeatureEnabled(mContext)
+ ? AVAILABLE
+ : UNSUPPORTED_ON_DEVICE;
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ final Preference preference = screen.findPreference(getPreferenceKey());
+ if (preference != null) {
+ preference.setOnPreferenceClickListener(preference1 -> {
+ final Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER);
+ final String packageName =
+ mContext.getString(R.string.config_wallpaper_picker_package);
+ if (!TextUtils.isEmpty(packageName)) {
+ intent.setPackage(packageName);
+ }
+ intent.putExtra("destination", "quick_affordances");
+ mContext.startActivity(intent);
+ return true;
+ });
+ refreshSummary(preference);
+ }
+ }
+
+ @Override
+ public CharSequence getSummary() {
+ return CustomizableLockScreenUtils.getQuickAffordanceSummary(mContext);
+ }
+}
diff --git a/src/com/android/settings/display/CustomizableLockScreenUtils.java b/src/com/android/settings/display/CustomizableLockScreenUtils.java
new file mode 100644
index 0000000000000000000000000000000000000000..2e9f53d9d0f26c22e632cf91374b64a6afa5da9c
--- /dev/null
+++ b/src/com/android/settings/display/CustomizableLockScreenUtils.java
@@ -0,0 +1,154 @@
+/*
+ * Copyright (C) 2022 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.ContentResolver;
+import android.content.Context;
+import android.database.Cursor;
+import android.net.Uri;
+import android.text.TextUtils;
+import android.util.Log;
+
+import androidx.annotation.Nullable;
+import androidx.annotation.VisibleForTesting;
+
+import com.android.settings.R;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/** Utilities for display settings related to customizable lock screen features. */
+public final class CustomizableLockScreenUtils {
+
+ private static final String TAG = "CustomizableLockScreenUtils";
+ private static final Uri BASE_URI = new Uri.Builder()
+ .scheme(ContentResolver.SCHEME_CONTENT)
+ .authority("com.android.systemui.customization")
+ .build();
+ @VisibleForTesting
+ static final Uri FLAGS_URI = BASE_URI.buildUpon()
+ .path("flags")
+ .build();
+ @VisibleForTesting
+ static final Uri SELECTIONS_URI = BASE_URI.buildUpon()
+ .appendPath("lockscreen_quickaffordance")
+ .appendPath("selections")
+ .build();
+ @VisibleForTesting
+ static final String NAME = "name";
+ @VisibleForTesting
+ static final String VALUE = "value";
+ @VisibleForTesting
+ static final String ENABLED_FLAG =
+ "is_custom_lock_screen_quick_affordances_feature_enabled";
+ @VisibleForTesting
+ static final String AFFORDANCE_NAME = "affordance_name";
+
+ private CustomizableLockScreenUtils() {}
+
+ /**
+ * Queries and returns whether the customizable lock screen quick affordances feature is enabled
+ * on the device.
+ *
+ * This is a slow, blocking call that shouldn't be made on the main thread.
+ */
+ public static boolean isFeatureEnabled(Context context) {
+ try (Cursor cursor = context.getContentResolver().query(
+ FLAGS_URI,
+ null,
+ null,
+ null)) {
+ if (cursor == null) {
+ Log.w(TAG, "Cursor was null!");
+ return false;
+ }
+
+ final int indexOfNameColumn = cursor.getColumnIndex(NAME);
+ final int indexOfValueColumn = cursor.getColumnIndex(VALUE);
+ if (indexOfNameColumn == -1 || indexOfValueColumn == -1) {
+ Log.w(TAG, "Cursor doesn't contain " + NAME + " or " + VALUE + "!");
+ return false;
+ }
+
+ while (cursor.moveToNext()) {
+ final String name = cursor.getString(indexOfNameColumn);
+ final int value = cursor.getInt(indexOfValueColumn);
+ if (TextUtils.equals(ENABLED_FLAG, name)) {
+ Log.d(TAG, ENABLED_FLAG + "=" + value);
+ return value == 1;
+ }
+ }
+
+ Log.w(TAG, "Flag with name \"" + ENABLED_FLAG + "\" not found!");
+ return false;
+ } catch (Exception e) {
+ Log.e(TAG, "Exception while querying quick affordance content provider", e);
+ return false;
+ }
+ }
+
+ /**
+ * Queries and returns a summary text for the currently-selected lock screen quick affordances.
+ *
+ *
This is a slow, blocking call that shouldn't be made on the main thread.
+ */
+ @Nullable
+ public static CharSequence getQuickAffordanceSummary(Context context) {
+ try (Cursor cursor = context.getContentResolver().query(
+ SELECTIONS_URI,
+ null,
+ null,
+ null)) {
+ if (cursor == null) {
+ Log.w(TAG, "Cursor was null!");
+ return null;
+ }
+
+ final int columnIndex = cursor.getColumnIndex(AFFORDANCE_NAME);
+ if (columnIndex == -1) {
+ Log.w(TAG, "Cursor doesn't contain \"" + AFFORDANCE_NAME + "\" column!");
+ return null;
+ }
+
+ final List affordanceNames = new ArrayList<>(cursor.getCount());
+ while (cursor.moveToNext()) {
+ final String affordanceName = cursor.getString(columnIndex);
+ if (!TextUtils.isEmpty(affordanceName)) {
+ affordanceNames.add(affordanceName);
+ }
+ }
+
+ // We don't display more than the first two items.
+ final int usableAffordanceNameCount = Math.min(2, affordanceNames.size());
+ final List arguments = new ArrayList<>(usableAffordanceNameCount);
+ if (!affordanceNames.isEmpty()) {
+ arguments.add(affordanceNames.get(0));
+ }
+ if (affordanceNames.size() > 1) {
+ arguments.add(affordanceNames.get(1));
+ }
+
+ return context.getResources().getQuantityString(
+ R.plurals.lockscreen_quick_affordances_summary,
+ usableAffordanceNameCount,
+ arguments.toArray());
+ } catch (Exception e) {
+ Log.e(TAG, "Exception while querying quick affordance content provider", e);
+ return null;
+ }
+ }
+}
diff --git a/src/com/android/settings/display/QRCodeScannerPreferenceController.java b/src/com/android/settings/display/QRCodeScannerPreferenceController.java
index 16e594a62d5fa9a0bc7b91a3111b4c12db78e2b9..cb022a74fa8888c06ac023dd673e1b161d279efb 100644
--- a/src/com/android/settings/display/QRCodeScannerPreferenceController.java
+++ b/src/com/android/settings/display/QRCodeScannerPreferenceController.java
@@ -87,6 +87,10 @@ public class QRCodeScannerPreferenceController extends TogglePreferenceControlle
@Override
public int getAvailabilityStatus() {
+ if (CustomizableLockScreenUtils.isFeatureEnabled(mContext)) {
+ return UNSUPPORTED_ON_DEVICE;
+ }
+
return isScannerActivityAvailable() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
diff --git a/src/com/android/settings/display/ScreenSaverPreferenceController.java b/src/com/android/settings/display/ScreenSaverPreferenceController.java
index 676a567f20232e63ea08227b649f5626d526812c..db4bc37054a9f35e50e8367c0deaa604504959b8 100644
--- a/src/com/android/settings/display/ScreenSaverPreferenceController.java
+++ b/src/com/android/settings/display/ScreenSaverPreferenceController.java
@@ -16,38 +16,42 @@ package com.android.settings.display;
import android.content.Context;
import android.os.UserManager;
-import androidx.preference.Preference;
-
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.dream.DreamSettings;
-import com.android.settingslib.core.AbstractPreferenceController;
-public class ScreenSaverPreferenceController extends AbstractPreferenceController implements
+public class ScreenSaverPreferenceController extends BasePreferenceController implements
PreferenceControllerMixin {
- private static final String KEY_SCREEN_SAVER = "screensaver";
+ private final boolean mDreamsDisabledByAmbientModeSuppression;
+
+ public ScreenSaverPreferenceController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
- public ScreenSaverPreferenceController(Context context) {
- super(context);
+ mDreamsDisabledByAmbientModeSuppression = context.getResources().getBoolean(
+ com.android.internal.R.bool.config_dreamsDisabledByAmbientModeSuppressionConfig);
}
@Override
- public boolean isAvailable() {
+ public int getAvailabilityStatus() {
final boolean dreamsSupported = mContext.getResources().getBoolean(
com.android.internal.R.bool.config_dreamsSupported);
- final boolean dreamsOnlyEnabledForSystemUser = mContext.getResources().getBoolean(
- com.android.internal.R.bool.config_dreamsOnlyEnabledForSystemUser);
- return dreamsSupported && (!dreamsOnlyEnabledForSystemUser || isSystemUser());
- }
-
- @Override
- public String getPreferenceKey() {
- return KEY_SCREEN_SAVER;
+ final boolean dreamsOnlyEnabledForDockUser = mContext.getResources().getBoolean(
+ com.android.internal.R.bool.config_dreamsOnlyEnabledForDockUser);
+ // TODO(b/257333623): Allow the Dock User to be non-SystemUser user in HSUM.
+ return (dreamsSupported && (!dreamsOnlyEnabledForDockUser || isSystemUser()))
+ ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
@Override
- public void updateState(Preference preference) {
- preference.setSummary(DreamSettings.getSummaryTextWithDreamName(mContext));
+ public CharSequence getSummary() {
+ if (mDreamsDisabledByAmbientModeSuppression
+ && AmbientDisplayAlwaysOnPreferenceController.isAodSuppressedByBedtime(mContext)) {
+ return mContext.getString(R.string.screensaver_settings_when_to_dream_bedtime);
+ } else {
+ return DreamSettings.getSummaryTextWithDreamName(mContext);
+ }
}
private boolean isSystemUser() {
diff --git a/src/com/android/settings/display/SmartAutoRotateController.java b/src/com/android/settings/display/SmartAutoRotateController.java
index 093c8459cd57ba84579544150ca4028033276211..18aabd80c9e25108468b5669598e2746e2a612da 100644
--- a/src/com/android/settings/display/SmartAutoRotateController.java
+++ b/src/com/android/settings/display/SmartAutoRotateController.java
@@ -180,6 +180,10 @@ public class SmartAutoRotateController extends TogglePreferenceController implem
* Returns true if there is a {@link RotationResolverService} available
*/
public static boolean isRotationResolverServiceAvailable(Context context) {
+ if (!context.getResources().getBoolean(
+ R.bool.config_auto_rotate_face_detection_available)) {
+ return false;
+ }
final PackageManager packageManager = context.getPackageManager();
final String resolvePackage = packageManager.getRotationResolverPackageName();
if (TextUtils.isEmpty(resolvePackage)) {
diff --git a/src/com/android/settings/display/WalletPrivacyPreferenceController.java b/src/com/android/settings/display/WalletPrivacyPreferenceController.java
index 92580f3d569a331dea6ef0ce6ca21fc0fbb8cb81..fe14a40a01aee2dc2aede039de49dc89f89f26ad 100644
--- a/src/com/android/settings/display/WalletPrivacyPreferenceController.java
+++ b/src/com/android/settings/display/WalletPrivacyPreferenceController.java
@@ -62,6 +62,10 @@ public class WalletPrivacyPreferenceController extends TogglePreferenceControlle
@Override
public int getAvailabilityStatus() {
+ if (CustomizableLockScreenUtils.isFeatureEnabled(mContext)) {
+ return UNSUPPORTED_ON_DEVICE;
+ }
+
return isEnabled() && isSecure() ? AVAILABLE : DISABLED_DEPENDENT_SETTING;
}
diff --git a/src/com/android/settings/dream/DreamSettings.java b/src/com/android/settings/dream/DreamSettings.java
index 1d12c1aecd5fbad21a77db418c13532bfbcc69b3..acc69731d0db1a260941747e168a2f568a064cad 100644
--- a/src/com/android/settings/dream/DreamSettings.java
+++ b/src/com/android/settings/dream/DreamSettings.java
@@ -90,12 +90,14 @@ public class DreamSettings extends DashboardFragment implements OnMainSwitchChan
}
}
- static int getDreamSettingDescriptionResId(@WhenToDream int dreamSetting) {
+ static int getDreamSettingDescriptionResId(@WhenToDream int dreamSetting,
+ boolean enabledOnBattery) {
switch (dreamSetting) {
case WHILE_CHARGING:
return R.string.screensaver_settings_summary_sleep;
case WHILE_DOCKED:
- return R.string.screensaver_settings_summary_dock;
+ return enabledOnBattery ? R.string.screensaver_settings_summary_dock
+ : R.string.screensaver_settings_summary_dock_and_charging;
case EITHER:
return R.string.screensaver_settings_summary_either_long;
case NEVER:
@@ -136,10 +138,11 @@ public class DreamSettings extends DashboardFragment implements OnMainSwitchChan
@VisibleForTesting
static CharSequence getSummaryTextFromBackend(DreamBackend backend, Context context) {
- if (!backend.isEnabled()) {
- return context.getString(R.string.screensaver_settings_summary_off);
+ if (backend.isEnabled()) {
+ return context.getString(R.string.screensaver_settings_summary_on,
+ backend.getActiveDreamName());
} else {
- return backend.getActiveDreamName();
+ return context.getString(R.string.screensaver_settings_summary_off);
}
}
diff --git a/src/com/android/settings/dream/WhenToDreamPicker.java b/src/com/android/settings/dream/WhenToDreamPicker.java
index 1c5e25ebac2a21824fd858de53f3365e03aba119..13cdadf19819c55d7d03c60de212688c24b16be3 100644
--- a/src/com/android/settings/dream/WhenToDreamPicker.java
+++ b/src/com/android/settings/dream/WhenToDreamPicker.java
@@ -32,12 +32,15 @@ public class WhenToDreamPicker extends RadioButtonPickerFragment {
private static final String TAG = "WhenToDreamPicker";
private DreamBackend mBackend;
+ private boolean mDreamsSupportedOnBattery;
@Override
public void onAttach(Context context) {
super.onAttach(context);
mBackend = DreamBackend.getInstance(context);
+ mDreamsSupportedOnBattery = getResources().getBoolean(
+ com.android.internal.R.bool.config_dreamsEnabledOnBattery);
}
@Override
@@ -69,11 +72,17 @@ public class WhenToDreamPicker extends RadioButtonPickerFragment {
}
private String[] entries() {
- return getResources().getStringArray(R.array.when_to_start_screensaver_entries);
+ if (mDreamsSupportedOnBattery) {
+ return getResources().getStringArray(R.array.when_to_start_screensaver_entries);
+ }
+ return getResources().getStringArray(R.array.when_to_start_screensaver_entries_no_battery);
}
private String[] keys() {
- return getResources().getStringArray(R.array.when_to_start_screensaver_values);
+ if (mDreamsSupportedOnBattery) {
+ return getResources().getStringArray(R.array.when_to_start_screensaver_values);
+ }
+ return getResources().getStringArray(R.array.when_to_start_screensaver_values_no_battery);
}
@Override
diff --git a/src/com/android/settings/dream/WhenToDreamPreferenceController.java b/src/com/android/settings/dream/WhenToDreamPreferenceController.java
index 4108e850538ecc2958872ce75af8018552ab762a..c3bae0064c98f10140ccb51c0115f3121d03b356 100644
--- a/src/com/android/settings/dream/WhenToDreamPreferenceController.java
+++ b/src/com/android/settings/dream/WhenToDreamPreferenceController.java
@@ -20,7 +20,10 @@ import android.content.Context;
import androidx.preference.Preference;
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.settings.R;
import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settings.display.AmbientDisplayAlwaysOnPreferenceController;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.dream.DreamBackend;
@@ -29,19 +32,39 @@ public class WhenToDreamPreferenceController extends AbstractPreferenceControlle
private static final String WHEN_TO_START = "when_to_start";
private final DreamBackend mBackend;
+ private final boolean mDreamsDisabledByAmbientModeSuppression;
+ private final boolean mDreamsEnabledOnBattery;
WhenToDreamPreferenceController(Context context) {
+ this(context, context.getResources().getBoolean(
+ com.android.internal.R.bool.config_dreamsDisabledByAmbientModeSuppressionConfig),
+ context.getResources().getBoolean(
+ com.android.internal.R.bool.config_dreamsEnabledOnBattery));
+ }
+
+ @VisibleForTesting
+ WhenToDreamPreferenceController(Context context,
+ boolean dreamsDisabledByAmbientModeSuppression,
+ boolean dreamsEnabledOnBattery) {
super(context);
mBackend = DreamBackend.getInstance(context);
+ mDreamsDisabledByAmbientModeSuppression = dreamsDisabledByAmbientModeSuppression;
+ mDreamsEnabledOnBattery = dreamsEnabledOnBattery;
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
- int resId = DreamSettings.getDreamSettingDescriptionResId(mBackend.getWhenToDreamSetting());
- preference.setSummary(preference.getContext().getString(resId));
+ if (mDreamsDisabledByAmbientModeSuppression
+ && AmbientDisplayAlwaysOnPreferenceController.isAodSuppressedByBedtime(mContext)) {
+ preference.setSummary(R.string.screensaver_settings_when_to_dream_bedtime);
+ } else {
+ final int resId = DreamSettings.getDreamSettingDescriptionResId(
+ mBackend.getWhenToDreamSetting(), mDreamsEnabledOnBattery);
+ preference.setSummary(resId);
+ }
}
@Override
diff --git a/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java b/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
index f6ed2a1a320cfa53087d071d2c563ac29dac7563..7d080c9cc931902c3331a420c83e4ccea8d627cf 100644
--- a/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
+++ b/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
@@ -227,7 +227,8 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
* Start packageName's battery detail page.
*/
public static void startBatteryDetailPage(
- Activity caller, Instrumentable instrumentable, String packageName) {
+ Activity caller, Instrumentable instrumentable, String packageName,
+ UserHandle userHandle) {
final Bundle args = new Bundle(3);
final PackageManager packageManager = caller.getPackageManager();
args.putString(EXTRA_PACKAGE_NAME, packageName);
@@ -243,6 +244,7 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
.setTitleRes(R.string.battery_details_title)
.setArguments(args)
.setSourceMetricsCategory(instrumentable.getMetricsCategory())
+ .setUserHandle(userHandle)
.launch();
}
@@ -299,7 +301,6 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
notifyBackupManager();
logMetricCategory(selectedPreference);
- mBatteryOptimizeUtils.setAppUsageState(selectedPreference);
Log.d(TAG, "Leave with mode: " + selectedPreference);
}
}
@@ -466,6 +467,7 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
updatePreferenceState(mUnrestrictedPreference, selectedKey);
updatePreferenceState(mOptimizePreference, selectedKey);
updatePreferenceState(mRestrictedPreference, selectedKey);
+ mBatteryOptimizeUtils.setAppUsageState(getSelectedPreference());
}
private void updatePreferenceState(SelectorWithWidgetPreference preference,
@@ -531,7 +533,6 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
private CharSequence getAppActiveTime(Bundle bundle) {
final long foregroundTimeMs = bundle.getLong(EXTRA_FOREGROUND_TIME);
final long backgroundTimeMs = bundle.getLong(EXTRA_BACKGROUND_TIME);
- final int consumedPower = bundle.getInt(EXTRA_POWER_USAGE_AMOUNT);
final int uid = bundle.getInt(EXTRA_UID, 0);
final String slotTime = bundle.getString(EXTRA_SLOT_TIME, null);
final long totalTimeMs = foregroundTimeMs + backgroundTimeMs;
@@ -543,9 +544,7 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
return null;
}
if (totalTimeMs == 0) {
- usageTimeSummary = getText(
- isChartGraphEnabled && consumedPower > 0 ? R.string.battery_usage_without_time
- : R.string.battery_not_usage);
+ usageTimeSummary = getText(R.string.battery_usage_without_time);
} else if (slotTime == null) {
// Shows summary text with last full charge if slot time is null.
usageTimeSummary = getAppFullChargeActiveSummary(
diff --git a/src/com/android/settings/fuelgauge/BatteryBroadcastReceiver.java b/src/com/android/settings/fuelgauge/BatteryBroadcastReceiver.java
index 436cde809a8904d33fd401253f66d109903a2106..665be1f0f2c38780ae21710f80ec081e34560f40 100644
--- a/src/com/android/settings/fuelgauge/BatteryBroadcastReceiver.java
+++ b/src/com/android/settings/fuelgauge/BatteryBroadcastReceiver.java
@@ -28,7 +28,6 @@ import androidx.annotation.IntDef;
import androidx.annotation.VisibleForTesting;
import com.android.settings.Utils;
-import com.android.settings.homepage.contextualcards.slices.BatteryFixSlice;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -99,6 +98,7 @@ public class BatteryBroadcastReceiver extends BroadcastReceiver {
final IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
intentFilter.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED);
+ intentFilter.addAction(BatteryUtils.BYPASS_DOCK_DEFENDER_ACTION);
final Intent intent = mContext.registerReceiver(this, intentFilter);
updateBatteryStatus(intent, true /* forceUpdate */);
@@ -133,8 +133,9 @@ public class BatteryBroadcastReceiver extends BroadcastReceiver {
mBatteryHealth = batteryHealth;
} else if (PowerManager.ACTION_POWER_SAVE_MODE_CHANGED.equals(intent.getAction())) {
mBatteryListener.onBatteryChanged(BatteryUpdateType.BATTERY_SAVER);
+ } else if (BatteryUtils.BYPASS_DOCK_DEFENDER_ACTION.equals(intent.getAction())) {
+ mBatteryListener.onBatteryChanged(BatteryUpdateType.BATTERY_STATUS);
}
}
- BatteryFixSlice.updateBatteryTipAvailabilityCache(mContext);
}
}
\ No newline at end of file
diff --git a/src/com/android/settings/fuelgauge/BatteryInfo.java b/src/com/android/settings/fuelgauge/BatteryInfo.java
index b1e4c34e6eaf4d15205fa452d393696bc923c9d0..da3bbe4d37923290f58bca93d751dd8c061752ab 100644
--- a/src/com/android/settings/fuelgauge/BatteryInfo.java
+++ b/src/com/android/settings/fuelgauge/BatteryInfo.java
@@ -49,6 +49,7 @@ public class BatteryInfo {
public CharSequence remainingLabel;
public int batteryLevel;
public int batteryStatus;
+ public int pluggedStatus;
public boolean discharging = true;
public boolean isOverheated;
public long remainingTimeUs = 0;
@@ -253,7 +254,8 @@ public class BatteryInfo {
info.mBatteryUsageStats = batteryUsageStats;
info.batteryLevel = Utils.getBatteryLevel(batteryBroadcast);
info.batteryPercentString = Utils.formatPercentage(info.batteryLevel);
- info.mCharging = batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) != 0;
+ info.pluggedStatus = batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0);
+ info.mCharging = info.pluggedStatus != 0;
info.averageTimeToDischarge = estimate.getAverageDischargeTime();
info.isOverheated = batteryBroadcast.getIntExtra(
BatteryManager.EXTRA_HEALTH, BatteryManager.BATTERY_HEALTH_UNKNOWN)
@@ -280,25 +282,33 @@ public class BatteryInfo {
BatteryManager.BATTERY_STATUS_UNKNOWN);
info.discharging = false;
info.suggestionLabel = null;
- if (info.isOverheated && status != BatteryManager.BATTERY_STATUS_FULL) {
+ int dockDefenderMode = BatteryUtils.getCurrentDockDefenderMode(context, info);
+ if ((info.isOverheated && status != BatteryManager.BATTERY_STATUS_FULL
+ && dockDefenderMode == BatteryUtils.DockDefenderMode.DISABLED)
+ || dockDefenderMode == BatteryUtils.DockDefenderMode.ACTIVE) {
+ // Battery defender active, battery charging paused
info.remainingLabel = null;
int chargingLimitedResId = R.string.power_charging_limited;
- info.chargeLabel =
- context.getString(chargingLimitedResId, info.batteryPercentString);
- } else if (chargeTimeMs > 0 && status != BatteryManager.BATTERY_STATUS_FULL) {
+ info.chargeLabel = context.getString(chargingLimitedResId, info.batteryPercentString);
+ } else if ((chargeTimeMs > 0 && status != BatteryManager.BATTERY_STATUS_FULL
+ && dockDefenderMode == BatteryUtils.DockDefenderMode.DISABLED)
+ || dockDefenderMode == BatteryUtils.DockDefenderMode.TEMPORARILY_BYPASSED) {
+ // Battery is charging to full
info.remainingTimeUs = PowerUtil.convertMsToUs(chargeTimeMs);
- final CharSequence timeString = StringUtil.formatElapsedTime(
- context,
- PowerUtil.convertUsToMs(info.remainingTimeUs),
- false /* withSeconds */,
+ final CharSequence timeString = StringUtil.formatElapsedTime(context,
+ (double) PowerUtil.convertUsToMs(info.remainingTimeUs), false /* withSeconds */,
true /* collapseTimeUnit */);
int resId = R.string.power_charging_duration;
- info.remainingLabel = context.getString(
- R.string.power_remaining_charging_duration_only, timeString);
+ info.remainingLabel = context.getString(R.string.power_remaining_charging_duration_only,
+ timeString);
info.chargeLabel = context.getString(resId, info.batteryPercentString, timeString);
+ } else if (dockDefenderMode == BatteryUtils.DockDefenderMode.FUTURE_BYPASS) {
+ // Dock defender will be triggered in the future, charging will be optimized.
+ info.chargeLabel = context.getString(R.string.power_charging_future_paused,
+ info.batteryPercentString);
} else {
- final String chargeStatusLabel =
- Utils.getBatteryStatus(context, batteryBroadcast, compactStatus);
+ final String chargeStatusLabel = Utils.getBatteryStatus(context, batteryBroadcast,
+ compactStatus);
info.remainingLabel = null;
info.chargeLabel = info.batteryLevel == 100 ? info.batteryPercentString :
resources.getString(R.string.power_charging, info.batteryPercentString,
diff --git a/src/com/android/settings/fuelgauge/BatteryOptimizeUtils.java b/src/com/android/settings/fuelgauge/BatteryOptimizeUtils.java
index dbfacc6907c2f7c68da5ad774a4e30f8d7f1a23b..e2a4efe9fb8a65fa435c937e89b5f978cba771a5 100644
--- a/src/com/android/settings/fuelgauge/BatteryOptimizeUtils.java
+++ b/src/com/android/settings/fuelgauge/BatteryOptimizeUtils.java
@@ -24,7 +24,6 @@ import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
import android.content.pm.ParceledListSlice;
import android.content.pm.UserInfo;
-import android.os.AsyncTask;
import android.os.UserHandle;
import android.os.UserManager;
import android.util.ArraySet;
@@ -222,10 +221,8 @@ public class BatteryOptimizeUtils {
mode == MODE_RESTRICTED ? AppOpsManager.MODE_IGNORED : AppOpsManager.MODE_ALLOWED;
final boolean allowListed = mode == MODE_UNRESTRICTED;
- AsyncTask.execute(() -> {
- setAppOptimizationModeInternal(appOpsManagerMode, allowListed, uid, packageName,
+ setAppOptimizationModeInternal(appOpsManagerMode, allowListed, uid, packageName,
batteryUtils, powerAllowlistBackend);
- });
}
private static void setAppOptimizationModeInternal(
diff --git a/src/com/android/settings/fuelgauge/BatteryUtils.java b/src/com/android/settings/fuelgauge/BatteryUtils.java
index a6c48a48d6bae57a0f73b4c44cb7c7f694fb11de..e9b72d0f51a474e7f68274dcdd7f83bd2ace92c3 100644
--- a/src/com/android/settings/fuelgauge/BatteryUtils.java
+++ b/src/com/android/settings/fuelgauge/BatteryUtils.java
@@ -24,6 +24,7 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.BatteryConsumer;
+import android.os.BatteryManager;
import android.os.BatteryStats;
import android.os.BatteryStatsManager;
import android.os.BatteryUsageStats;
@@ -33,6 +34,7 @@ import android.os.Process;
import android.os.SystemClock;
import android.os.UidBatteryConsumer;
import android.os.UserHandle;
+import android.provider.Settings;
import android.util.Log;
import androidx.annotation.IntDef;
@@ -72,6 +74,11 @@ public class BatteryUtils {
/** Special UID for aggregated other users. */
public static final long UID_OTHER_USERS = Long.MIN_VALUE;
+ /** Flag to check if the dock defender mode has been temporarily bypassed */
+ public static final String SETTINGS_GLOBAL_DOCK_DEFENDER_BYPASS = "dock_defender_bypass";
+
+ public static final String BYPASS_DOCK_DEFENDER_ACTION = "battery.dock.defender.bypass";
+
@Retention(RetentionPolicy.SOURCE)
@IntDef({StatusType.SCREEN_USAGE,
StatusType.FOREGROUND,
@@ -85,6 +92,18 @@ public class BatteryUtils {
int ALL = 3;
}
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef({DockDefenderMode.FUTURE_BYPASS,
+ DockDefenderMode.ACTIVE,
+ DockDefenderMode.TEMPORARILY_BYPASSED,
+ DockDefenderMode.DISABLED})
+ public @interface DockDefenderMode {
+ int FUTURE_BYPASS = 0;
+ int ACTIVE = 1;
+ int TEMPORARILY_BYPASSED = 2;
+ int DISABLED = 3;
+ }
+
private static final String TAG = "BatteryUtils";
private static BatteryUtils sInstance;
@@ -570,4 +589,21 @@ public class BatteryUtils {
return -1L;
}
+
+ /** Gets the current dock defender mode */
+ public static int getCurrentDockDefenderMode(Context context, BatteryInfo batteryInfo) {
+ if (batteryInfo.pluggedStatus == BatteryManager.BATTERY_PLUGGED_DOCK) {
+ if (Settings.Global.getInt(context.getContentResolver(),
+ SETTINGS_GLOBAL_DOCK_DEFENDER_BYPASS, 0) == 1) {
+ return DockDefenderMode.TEMPORARILY_BYPASSED;
+ } else if (batteryInfo.isOverheated && FeatureFactory.getFactory(context)
+ .getPowerUsageFeatureProvider(context)
+ .isExtraDefend()) {
+ return DockDefenderMode.ACTIVE;
+ } else if (!batteryInfo.isOverheated) {
+ return DockDefenderMode.FUTURE_BYPASS;
+ }
+ }
+ return DockDefenderMode.DISABLED;
+ }
}
diff --git a/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java b/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java
index 94a93b83be016792b0fc55a1b70964bf01baa855..9b6f50f17dc5277baea2e16acf3c4132db6f82b1 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java
@@ -147,7 +147,7 @@ public interface PowerUsageFeatureProvider {
/**
* Gets a intent for one time bypass charge limited to resume charging.
*/
- Intent getResumeChargeIntent();
+ Intent getResumeChargeIntent(boolean isDockDefender);
/**
* Returns battery history data with corresponding timestamp key.
diff --git a/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java b/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java
index 0adfc9d15371b21e334e1d67ee506abd2962d9a2..cc802e8d30aed4f6419d1074a7ff2fca0a2c2a8a 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java
@@ -156,7 +156,7 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider
}
@Override
- public Intent getResumeChargeIntent() {
+ public Intent getResumeChargeIntent(boolean isDockDefender) {
return null;
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragment.java b/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragment.java
index d4c00a44cd2eb02cc402b218a9820d7e48ed037a..5fd3905649fe5a7bd052cd608d6fba397c3399a2 100644
--- a/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragment.java
+++ b/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragment.java
@@ -43,7 +43,6 @@ import com.android.settings.fuelgauge.batterytip.tips.HighUsageTip;
import com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip;
import com.android.settings.fuelgauge.batterytip.tips.UnrestrictAppTip;
-import java.text.NumberFormat;
import java.util.List;
/**
@@ -142,29 +141,6 @@ public class BatteryTipDialogFragment extends InstrumentedDialogFragment impleme
.setPositiveButton(R.string.battery_tip_unrestrict_app_dialog_ok, this)
.setNegativeButton(R.string.battery_tip_unrestrict_app_dialog_cancel, null)
.create();
- case BatteryTip.TipType.BATTERY_DEFENDER:
- mMetricsFeatureProvider.action(context,
- SettingsEnums.ACTION_TIP_BATTERY_DEFENDER, mMetricsKey);
- final double chargeLimitLevel = 0.8f;
- final String percentage =
- NumberFormat.getPercentInstance().format(chargeLimitLevel);
- final String message = context.getString(
- R.string.battery_tip_limited_temporarily_dialog_msg, percentage);
- final boolean isPluggedIn = isPluggedIn();
- final AlertDialog.Builder dialogBuilder =
- new AlertDialog.Builder(context)
- .setTitle(R.string.battery_tip_limited_temporarily_title)
- .setMessage(message);
- if (isPluggedIn) {
- dialogBuilder
- .setPositiveButton(
- R.string.battery_tip_limited_temporarily_dialog_resume_charge,
- this)
- .setNegativeButton(R.string.okay, null);
- } else {
- dialogBuilder.setPositiveButton(R.string.okay, null);
- }
- return dialogBuilder.create();
default:
throw new IllegalArgumentException("unknown type " + mBatteryTip.getType());
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/BatteryTipLoader.java b/src/com/android/settings/fuelgauge/batterytip/BatteryTipLoader.java
index 95145ba8216f16ec9d8260a931e42c93d3761e2d..7bdc5d5686a37610a53e0681a501869dfc144af6 100644
--- a/src/com/android/settings/fuelgauge/batterytip/BatteryTipLoader.java
+++ b/src/com/android/settings/fuelgauge/batterytip/BatteryTipLoader.java
@@ -24,6 +24,7 @@ import androidx.annotation.VisibleForTesting;
import com.android.settings.fuelgauge.BatteryInfo;
import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settings.fuelgauge.batterytip.detectors.BatteryDefenderDetector;
+import com.android.settings.fuelgauge.batterytip.detectors.DockDefenderDetector;
import com.android.settings.fuelgauge.batterytip.detectors.EarlyWarningDetector;
import com.android.settings.fuelgauge.batterytip.detectors.HighUsageDetector;
import com.android.settings.fuelgauge.batterytip.detectors.LowBatteryDetector;
@@ -74,6 +75,7 @@ public class BatteryTipLoader extends AsyncLoaderCompat> {
tips.add(new EarlyWarningDetector(policy, context).detect());
tips.add(new BatteryDefenderDetector(
batteryInfo, context.getApplicationContext()).detect());
+ tips.add(new DockDefenderDetector(batteryInfo, context.getApplicationContext()).detect());
Collections.sort(tips);
return tips;
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/actions/BatteryDefenderAction.java b/src/com/android/settings/fuelgauge/batterytip/actions/BatteryDefenderAction.java
deleted file mode 100644
index 824b6bee5ca73397ff66dd8ebb4267c5f70b30be..0000000000000000000000000000000000000000
--- a/src/com/android/settings/fuelgauge/batterytip/actions/BatteryDefenderAction.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2020 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.fuelgauge.batterytip.actions;
-
-import android.content.Intent;
-
-import com.android.settings.SettingsActivity;
-import com.android.settings.overlay.FeatureFactory;
-
-/**
- * Action to open the Support Center article
- */
-public class BatteryDefenderAction extends BatteryTipAction {
- private SettingsActivity mSettingsActivity;
-
- public BatteryDefenderAction(SettingsActivity settingsActivity) {
- super(settingsActivity.getApplicationContext());
- mSettingsActivity = settingsActivity;
- }
-
- @Override
- public void handlePositiveAction(int metricsKey) {
- final Intent intent = FeatureFactory.getFactory(mContext)
- .getPowerUsageFeatureProvider(mContext).getResumeChargeIntent();
- if (intent != null) {
- mContext.sendBroadcast(intent);
- }
- }
-}
diff --git a/src/com/android/settings/fuelgauge/batterytip/detectors/BatteryDefenderDetector.java b/src/com/android/settings/fuelgauge/batterytip/detectors/BatteryDefenderDetector.java
index 87d4a0b44a5197f7ab8836df3d07507910adb444..08df2e494f63178c951b3bd5f307d6a4e3ba2fb8 100644
--- a/src/com/android/settings/fuelgauge/batterytip/detectors/BatteryDefenderDetector.java
+++ b/src/com/android/settings/fuelgauge/batterytip/detectors/BatteryDefenderDetector.java
@@ -37,11 +37,10 @@ public class BatteryDefenderDetector implements BatteryTipDetector {
@Override
public BatteryTip detect() {
- if (mBatteryInfo.isOverheated) {
- final boolean extraDefend = FeatureFactory.getFactory(mContext)
- .getPowerUsageFeatureProvider(mContext)
- .isExtraDefend();
- return new BatteryDefenderTip(BatteryTip.StateType.NEW, extraDefend);
+ if (mBatteryInfo.isOverheated && !FeatureFactory.getFactory(mContext)
+ .getPowerUsageFeatureProvider(mContext)
+ .isExtraDefend()) {
+ return new BatteryDefenderTip(BatteryTip.StateType.NEW);
}
return new BatteryDefenderTip(BatteryTip.StateType.INVISIBLE);
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/detectors/DockDefenderDetector.java b/src/com/android/settings/fuelgauge/batterytip/detectors/DockDefenderDetector.java
new file mode 100644
index 0000000000000000000000000000000000000000..8a839d392d80bbf75b3711be953d0f8ef6f8f341
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/batterytip/detectors/DockDefenderDetector.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2022 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.fuelgauge.batterytip.detectors;
+
+import android.content.Context;
+
+import com.android.settings.fuelgauge.BatteryInfo;
+import com.android.settings.fuelgauge.BatteryUtils;
+import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
+import com.android.settings.fuelgauge.batterytip.tips.DockDefenderTip;
+
+/**
+ * Detect whether the dock defender mode is enabled.
+ */
+public class DockDefenderDetector implements BatteryTipDetector {
+ private final BatteryInfo mBatteryInfo;
+ private final Context mContext;
+
+ public DockDefenderDetector(BatteryInfo batteryInfo, Context context) {
+ mBatteryInfo = batteryInfo;
+ mContext = context;
+ }
+
+ @Override
+ public BatteryTip detect() {
+ int mode = BatteryUtils.getCurrentDockDefenderMode(mContext, mBatteryInfo);
+ return new DockDefenderTip(
+ mode != BatteryUtils.DockDefenderMode.DISABLED
+ ? BatteryTip.StateType.NEW
+ : BatteryTip.StateType.INVISIBLE,
+ mode);
+ }
+
+}
diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/BatteryDefenderTip.java b/src/com/android/settings/fuelgauge/batterytip/tips/BatteryDefenderTip.java
index 2fb565008348aa4543270d0492325430835d5ec5..1ccc29c18e3e06411d6cd217ecd30fa8543379b5 100644
--- a/src/com/android/settings/fuelgauge/batterytip/tips/BatteryDefenderTip.java
+++ b/src/com/android/settings/fuelgauge/batterytip/tips/BatteryDefenderTip.java
@@ -32,24 +32,15 @@ import com.android.settings.widget.CardPreference;
import com.android.settingslib.HelpUtils;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
-import java.text.NumberFormat;
-
/**
* Tip to show current battery is overheated
*/
public class BatteryDefenderTip extends BatteryTip {
private static final String TAG = "BatteryDefenderTip";
- private boolean mExtraDefend = false;
public BatteryDefenderTip(@StateType int state) {
- this(state, false);
- }
-
- public BatteryDefenderTip(@StateType int state, boolean extraDefend) {
- super(TipType.BATTERY_DEFENDER, state, true /* showDialog */);
- mExtraDefend = extraDefend;
- mShowDialog = false;
+ super(TipType.BATTERY_DEFENDER, state, false /* showDialog */);
}
private BatteryDefenderTip(Parcel in) {
@@ -63,14 +54,6 @@ public class BatteryDefenderTip extends BatteryTip {
@Override
public CharSequence getSummary(Context context) {
- if (mExtraDefend) {
- final int extraValue = context.getResources()
- .getInteger(R.integer.config_battery_extra_tip_value);
- final String extraPercentage = NumberFormat.getPercentInstance()
- .format(extraValue * 0.01f);
- return context.getString(
- R.string.battery_tip_limited_temporarily_extra_summary, extraPercentage);
- }
return context.getString(R.string.battery_tip_limited_temporarily_summary);
}
@@ -131,7 +114,7 @@ public class BatteryDefenderTip extends BatteryTip {
final Intent intent =
FeatureFactory.getFactory(context)
.getPowerUsageFeatureProvider(context)
- .getResumeChargeIntent();
+ .getResumeChargeIntent(false);
if (intent != null) {
context.sendBroadcast(intent);
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTip.java b/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTip.java
index 5aee0291e4dace2ed3aaeb079f1eba15eb9c4759..fcf5e09ba1b09f4a2aa864a18bb2a7fb07e72076 100644
--- a/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTip.java
+++ b/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTip.java
@@ -58,7 +58,8 @@ public abstract class BatteryTip implements Comparable, Parcelable {
TipType.REDUCED_BATTERY,
TipType.LOW_BATTERY,
TipType.REMOVE_APP_RESTRICTION,
- TipType.BATTERY_DEFENDER})
+ TipType.BATTERY_DEFENDER,
+ TipType.DOCK_DEFENDER})
public @interface TipType {
int SMART_BATTERY_MANAGER = 0;
int APP_RESTRICTION = 1;
@@ -69,6 +70,7 @@ public abstract class BatteryTip implements Comparable, Parcelable {
int SUMMARY = 6;
int REMOVE_APP_RESTRICTION = 7;
int BATTERY_DEFENDER = 8;
+ int DOCK_DEFENDER = 9;
}
@VisibleForTesting
@@ -78,12 +80,13 @@ public abstract class BatteryTip implements Comparable, Parcelable {
TIP_ORDER.append(TipType.BATTERY_SAVER, 0);
TIP_ORDER.append(TipType.LOW_BATTERY, 1);
TIP_ORDER.append(TipType.BATTERY_DEFENDER, 2);
- TIP_ORDER.append(TipType.APP_RESTRICTION, 3);
- TIP_ORDER.append(TipType.HIGH_DEVICE_USAGE, 4);
- TIP_ORDER.append(TipType.SUMMARY, 5);
- TIP_ORDER.append(TipType.SMART_BATTERY_MANAGER, 6);
- TIP_ORDER.append(TipType.REDUCED_BATTERY, 7);
- TIP_ORDER.append(TipType.REMOVE_APP_RESTRICTION, 8);
+ TIP_ORDER.append(TipType.DOCK_DEFENDER, 3);
+ TIP_ORDER.append(TipType.APP_RESTRICTION, 4);
+ TIP_ORDER.append(TipType.HIGH_DEVICE_USAGE, 5);
+ TIP_ORDER.append(TipType.SUMMARY, 6);
+ TIP_ORDER.append(TipType.SMART_BATTERY_MANAGER, 7);
+ TIP_ORDER.append(TipType.REDUCED_BATTERY, 8);
+ TIP_ORDER.append(TipType.REMOVE_APP_RESTRICTION, 9);
}
private static final String KEY_PREFIX = "key_battery_tip";
diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/DockDefenderTip.java b/src/com/android/settings/fuelgauge/batterytip/tips/DockDefenderTip.java
new file mode 100644
index 0000000000000000000000000000000000000000..bc0ba080fc69838083214d49f3f6d5255540beab
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/batterytip/tips/DockDefenderTip.java
@@ -0,0 +1,179 @@
+/*
+ * Copyright (C) 2022 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.fuelgauge.batterytip.tips;
+
+import android.app.settings.SettingsEnums;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Parcel;
+import android.util.Log;
+
+import androidx.preference.Preference;
+
+import com.android.settings.R;
+import com.android.settings.fuelgauge.BatteryUtils;
+import com.android.settings.fuelgauge.BatteryUtils.DockDefenderMode;
+import com.android.settings.overlay.FeatureFactory;
+import com.android.settings.widget.CardPreference;
+import com.android.settingslib.HelpUtils;
+import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
+
+/**
+ * Tip to show dock defender status
+ */
+public class DockDefenderTip extends BatteryTip {
+ private static final String TAG = "DockDefenderTip";
+ private int mMode;
+
+ public DockDefenderTip(@StateType int state, @DockDefenderMode int mode) {
+ super(TipType.DOCK_DEFENDER, state, false);
+ mMode = mode;
+ }
+
+ private DockDefenderTip(Parcel in) {
+ super(in);
+ }
+
+ public int getMode() {
+ return mMode;
+ }
+
+ @Override
+ public CharSequence getTitle(Context context) {
+ switch (mMode) {
+ case DockDefenderMode.FUTURE_BYPASS:
+ return context.getString(R.string.battery_tip_dock_defender_future_bypass_title);
+ case DockDefenderMode.ACTIVE:
+ return context.getString(R.string.battery_tip_dock_defender_active_title);
+ case DockDefenderMode.TEMPORARILY_BYPASSED:
+ return context.getString(
+ R.string.battery_tip_dock_defender_temporarily_bypassed_title);
+ default:
+ return null;
+ }
+ }
+
+ @Override
+ public CharSequence getSummary(Context context) {
+ switch (mMode) {
+ case DockDefenderMode.FUTURE_BYPASS:
+ return context.getString(R.string.battery_tip_dock_defender_future_bypass_summary);
+ case DockDefenderMode.ACTIVE:
+ return context.getString(R.string.battery_tip_dock_defender_active_summary);
+ case DockDefenderMode.TEMPORARILY_BYPASSED:
+ return context.getString(
+ R.string.battery_tip_dock_defender_temporarily_bypassed_summary);
+ default:
+ return null;
+ }
+ }
+
+ @Override
+ public int getIconId() {
+ return mMode == DockDefenderMode.ACTIVE ? R.drawable.ic_battery_status_protected_24dp :
+ R.drawable.ic_battery_dock_defender_untriggered_24dp;
+ }
+
+ @Override
+ public void updateState(BatteryTip tip) {
+ mState = tip.mState;
+ if (tip instanceof DockDefenderTip) {
+ mMode = ((DockDefenderTip) tip).mMode;
+ }
+ }
+
+ @Override
+ public void log(Context context, MetricsFeatureProvider metricsFeatureProvider) {
+ metricsFeatureProvider.action(context, SettingsEnums.ACTION_DOCK_DEFENDER_TIP,
+ mState);
+ }
+
+ @Override
+ public void updatePreference(Preference preference) {
+ super.updatePreference(preference);
+ final Context context = preference.getContext();
+
+ CardPreference cardPreference = castToCardPreferenceSafely(preference);
+ if (cardPreference == null) {
+ Log.e(TAG, "cast Preference to CardPreference failed");
+ return;
+ }
+
+ cardPreference.setSelectable(false);
+ switch (mMode) {
+ case DockDefenderMode.FUTURE_BYPASS:
+ case DockDefenderMode.ACTIVE:
+ cardPreference.setPrimaryButtonText(
+ context.getString(R.string.battery_tip_charge_to_full_button));
+ cardPreference.setPrimaryButtonClickListener(unused -> {
+ resumeCharging(context);
+ mMode = DockDefenderMode.TEMPORARILY_BYPASSED;
+ context.sendBroadcast(new Intent().setAction(
+ BatteryUtils.BYPASS_DOCK_DEFENDER_ACTION).setPackage(
+ context.getPackageName()).addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY
+ | Intent.FLAG_RECEIVER_FOREGROUND));
+ updatePreference(preference);
+ });
+ cardPreference.setPrimaryButtonVisible(true);
+ break;
+ case DockDefenderMode.TEMPORARILY_BYPASSED:
+ cardPreference.setPrimaryButtonVisible(false);
+ break;
+ default:
+ cardPreference.setVisible(false);
+ return;
+ }
+
+ cardPreference.setSecondaryButtonText(context.getString(R.string.learn_more));
+ cardPreference.setSecondaryButtonClickListener(
+ button -> button.startActivityForResult(
+ HelpUtils.getHelpIntent(
+ context,
+ context.getString(R.string.help_url_dock_defender),
+ /* backupContext */ ""), /* requestCode */ 0));
+ cardPreference.setSecondaryButtonVisible(true);
+ cardPreference.setSecondaryButtonContentDescription(context.getString(
+ R.string.battery_tip_limited_temporarily_sec_button_content_description));
+
+ }
+
+ private CardPreference castToCardPreferenceSafely(Preference preference) {
+ return preference instanceof CardPreference ? (CardPreference) preference : null;
+ }
+
+ private void resumeCharging(Context context) {
+ final Intent intent =
+ FeatureFactory.getFactory(context)
+ .getPowerUsageFeatureProvider(context)
+ .getResumeChargeIntent(true);
+ if (intent != null) {
+ context.sendBroadcast(intent);
+ }
+
+ Log.i(TAG, "send resume charging broadcast intent=" + intent);
+ }
+
+ public static final Creator CREATOR = new Creator() {
+ public BatteryTip createFromParcel(Parcel in) {
+ return new DockDefenderTip(in);
+ }
+
+ public BatteryTip[] newArray(int size) {
+ return new DockDefenderTip[size];
+ }
+ };
+}
diff --git a/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceController.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceController.java
index 2c924885c3ba62cd66edcae7e630b806d8703375..56da0f47932da6409fd08d96ba1a653e44a4fce5 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceController.java
@@ -108,6 +108,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
private boolean mIs24HourFormat;
private boolean mIsFooterPrefAdded = false;
+ private boolean mHourlyChartVisible = true;
private View mBatteryChartViewGroup;
private View mCategoryTitleView;
private PreferenceScreen mPreferenceScreen;
@@ -690,9 +691,10 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
}
private void animateBatteryHourlyChartView(final boolean visible) {
- if (mHourlyChartView == null) {
+ if (mHourlyChartView == null || mHourlyChartVisible == visible) {
return;
}
+ mHourlyChartVisible = visible;
if (visible) {
mHourlyChartView.setVisibility(View.VISIBLE);
diff --git a/src/com/android/settings/fuelgauge/batteryusage/DataProcessor.java b/src/com/android/settings/fuelgauge/batteryusage/DataProcessor.java
index b9c3a6ff7f3e621cc4819c6c7966d7d19e491ee9..86533ba07c38c2701d382db09c0e13e4c7cc56c9 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/DataProcessor.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/DataProcessor.java
@@ -67,6 +67,7 @@ public final class DataProcessor {
private static final int MAX_DIFF_SECONDS_OF_UPPER_TIMESTAMP = 5;
// Maximum total time value for each hourly slot cumulative data at most 2 hours.
private static final float TOTAL_HOURLY_TIME_THRESHOLD = DateUtils.HOUR_IN_MILLIS * 2;
+ private static final long MIN_TIME_SLOT = DateUtils.HOUR_IN_MILLIS * 2;
private static final Map EMPTY_BATTERY_MAP = new HashMap<>();
private static final BatteryHistEntry EMPTY_BATTERY_HIST_ENTRY =
new BatteryHistEntry(new ContentValues());
@@ -270,13 +271,31 @@ public final class DataProcessor {
}
final long startTime = timestampList.get(0);
final long endTime = timestampList.get(timestampList.size() - 1);
+ // If the timestamp diff is smaller than MIN_TIME_SLOT, returns the empty list directly.
+ if (endTime - startTime < MIN_TIME_SLOT) {
+ return dailyTimestampList;
+ }
long nextDay = getTimestampOfNextDay(startTime);
- dailyTimestampList.add(startTime);
+ // Only if the timestamp diff in the first day is bigger than MIN_TIME_SLOT, start from the
+ // first day. Otherwise, start from the second day.
+ if (nextDay - startTime >= MIN_TIME_SLOT) {
+ dailyTimestampList.add(startTime);
+ }
while (nextDay < endTime) {
dailyTimestampList.add(nextDay);
nextDay += DateUtils.DAY_IN_MILLIS;
}
- dailyTimestampList.add(endTime);
+ final long lastDailyTimestamp = dailyTimestampList.get(dailyTimestampList.size() - 1);
+ // Only if the timestamp diff in the last day is bigger than MIN_TIME_SLOT, add the
+ // last day.
+ if (endTime - lastDailyTimestamp >= MIN_TIME_SLOT) {
+ dailyTimestampList.add(endTime);
+ }
+ // The dailyTimestampList must have the start and end timestamp, otherwise, return an empty
+ // list.
+ if (dailyTimestampList.size() < MIN_TIMESTAMP_DATA_SIZE) {
+ return new ArrayList<>();
+ }
return dailyTimestampList;
}
@@ -721,7 +740,7 @@ public final class DataProcessor {
final List hourlyTimestampsPerDay = new ArrayList<>();
while (currentTimestamp <= dailyEndTimestamp) {
hourlyTimestampsPerDay.add(currentTimestamp);
- currentTimestamp += 2 * DateUtils.HOUR_IN_MILLIS;
+ currentTimestamp += MIN_TIME_SLOT;
}
hourlyTimestamps.add(hourlyTimestampsPerDay);
}
diff --git a/src/com/android/settings/fuelgauge/batteryusage/PowerUsageAdvanced.java b/src/com/android/settings/fuelgauge/batteryusage/PowerUsageAdvanced.java
index b88d85ddd1fbb3bd789a4551fefb63f64f4ed3d4..db904730a277c6f208fcbb8b35481effc49a532c 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/PowerUsageAdvanced.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/PowerUsageAdvanced.java
@@ -55,7 +55,6 @@ public class PowerUsageAdvanced extends PowerUsageBase {
private static final String KEY_REFRESH_TYPE = "refresh_type";
private static final String KEY_BATTERY_GRAPH = "battery_graph";
private static final String KEY_APP_LIST = "app_list";
- private static final int LOADER_BATTERY_USAGE_STATS = 2;
@VisibleForTesting
BatteryHistoryPreference mHistPref;
@@ -188,7 +187,7 @@ public class PowerUsageAdvanced extends PowerUsageBase {
// Uses customized battery history loader if chart design is enabled.
if (mIsChartGraphEnabled && !mIsChartDataLoaded) {
mIsChartDataLoaded = true;
- getLoaderManager().restartLoader(LOADER_BATTERY_USAGE_STATS, bundle,
+ restartLoader(LoaderIndex.BATTERY_HISTORY_LOADER, bundle,
mBatteryHistoryLoaderCallbacks);
} else if (!mIsChartGraphEnabled) {
super.restartBatteryStatsLoader(refreshType);
diff --git a/src/com/android/settings/fuelgauge/batteryusage/PowerUsageBase.java b/src/com/android/settings/fuelgauge/batteryusage/PowerUsageBase.java
index ccefdf2c4db59fae0d1655394b83b2cd7a626e63..ed3a921535279cdff8087ba6f0a76447048a3e2f 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/PowerUsageBase.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/PowerUsageBase.java
@@ -24,6 +24,7 @@ import android.os.Bundle;
import android.os.UserManager;
import android.util.Log;
+import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import androidx.loader.app.LoaderManager;
@@ -33,17 +34,19 @@ import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.fuelgauge.BatteryBroadcastReceiver;
import com.android.settings.fuelgauge.BatteryUtils;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
/**
* Common base class for things that need to show the battery usage graph.
*/
public abstract class PowerUsageBase extends DashboardFragment {
-
private static final String TAG = "PowerUsageBase";
- private static final String KEY_REFRESH_TYPE = "refresh_type";
- private static final String KEY_INCLUDE_HISTORY = "include_history";
-
- private static final int LOADER_BATTERY_USAGE_STATS = 1;
+ @VisibleForTesting
+ static final String KEY_REFRESH_TYPE = "refresh_type";
+ @VisibleForTesting
+ static final String KEY_INCLUDE_HISTORY = "include_history";
@VisibleForTesting
BatteryUsageStats mBatteryUsageStats;
@@ -55,6 +58,21 @@ public abstract class PowerUsageBase extends DashboardFragment {
final BatteryUsageStatsLoaderCallbacks mBatteryUsageStatsLoaderCallbacks =
new BatteryUsageStatsLoaderCallbacks();
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef({
+ LoaderIndex.BATTERY_USAGE_STATS_LOADER,
+ LoaderIndex.BATTERY_INFO_LOADER,
+ LoaderIndex.BATTERY_TIP_LOADER,
+ LoaderIndex.BATTERY_HISTORY_LOADER
+
+ })
+ public @interface LoaderIndex {
+ int BATTERY_USAGE_STATS_LOADER = 0;
+ int BATTERY_INFO_LOADER = 1;
+ int BATTERY_TIP_LOADER = 2;
+ int BATTERY_HISTORY_LOADER = 3;
+ }
+
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
@@ -91,10 +109,28 @@ public abstract class PowerUsageBase extends DashboardFragment {
final Bundle bundle = new Bundle();
bundle.putInt(KEY_REFRESH_TYPE, refreshType);
bundle.putBoolean(KEY_INCLUDE_HISTORY, isBatteryHistoryNeeded());
- getLoaderManager().restartLoader(LOADER_BATTERY_USAGE_STATS, bundle,
+ restartLoader(LoaderIndex.BATTERY_USAGE_STATS_LOADER, bundle,
mBatteryUsageStatsLoaderCallbacks);
}
+ protected LoaderManager getLoaderManagerForCurrentFragment() {
+ return LoaderManager.getInstance(this);
+ }
+
+ protected void restartLoader(int loaderId, Bundle bundle,
+ LoaderManager.LoaderCallbacks> loaderCallbacks) {
+ LoaderManager loaderManager = getLoaderManagerForCurrentFragment();
+ Loader> loader = loaderManager.getLoader(
+ loaderId);
+ if (loader != null && !loader.isReset()) {
+ loaderManager.restartLoader(loaderId, bundle,
+ loaderCallbacks);
+ } else {
+ loaderManager.initLoader(loaderId, bundle,
+ loaderCallbacks);
+ }
+ }
+
protected void onLoadFinished(@BatteryUpdateType int refreshType) {
refreshUi(refreshType);
}
diff --git a/src/com/android/settings/fuelgauge/batteryusage/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/batteryusage/PowerUsageSummary.java
index bca32a78f8f86a336768894d6c1aaaa567722c7d..f26649278866e4ed79560f931af1f5503ebfd89c 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/PowerUsageSummary.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/PowerUsageSummary.java
@@ -64,11 +64,6 @@ public class PowerUsageSummary extends PowerUsageBase implements
@VisibleForTesting
static final String KEY_BATTERY_USAGE = "battery_usage_summary";
- @VisibleForTesting
- static final int BATTERY_INFO_LOADER = 1;
- @VisibleForTesting
- static final int BATTERY_TIP_LOADER = 2;
-
@VisibleForTesting
PowerUsageFeatureProvider mPowerFeatureProvider;
@VisibleForTesting
@@ -241,7 +236,7 @@ public class PowerUsageSummary extends PowerUsageBase implements
@VisibleForTesting
void restartBatteryTipLoader() {
- getLoaderManager().restartLoader(BATTERY_TIP_LOADER, Bundle.EMPTY, mBatteryTipsCallbacks);
+ restartLoader(LoaderIndex.BATTERY_TIP_LOADER, Bundle.EMPTY, mBatteryTipsCallbacks);
}
@VisibleForTesting
@@ -274,8 +269,7 @@ public class PowerUsageSummary extends PowerUsageBase implements
if (!mIsBatteryPresent) {
return;
}
- getLoaderManager().restartLoader(BATTERY_INFO_LOADER, Bundle.EMPTY,
- mBatteryInfoLoaderCallbacks);
+ restartLoader(LoaderIndex.BATTERY_INFO_LOADER, Bundle.EMPTY, mBatteryInfoLoaderCallbacks);
}
@VisibleForTesting
diff --git a/src/com/android/settings/homepage/SettingsHomepageActivity.java b/src/com/android/settings/homepage/SettingsHomepageActivity.java
index 8e14c5a44ea30caa23177c7d6e4721d4b2e3373c..2961abbd89527321ad3186ea4f2102cac1943eef 100644
--- a/src/com/android/settings/homepage/SettingsHomepageActivity.java
+++ b/src/com/android/settings/homepage/SettingsHomepageActivity.java
@@ -27,9 +27,13 @@ import android.app.ActivityManager;
import android.app.settings.SettingsEnums;
import android.content.ComponentName;
import android.content.Intent;
+import android.content.pm.ActivityInfo;
+import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.content.res.Configuration;
import android.os.Bundle;
+import android.os.Process;
+import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
import android.text.TextUtils;
@@ -43,6 +47,7 @@ import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.Toolbar;
+import androidx.annotation.VisibleForTesting;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowCompat;
@@ -65,6 +70,8 @@ import com.android.settings.core.CategoryMixin;
import com.android.settings.core.FeatureFlags;
import com.android.settings.homepage.contextualcards.ContextualCardsFragment;
import com.android.settings.overlay.FeatureFactory;
+import com.android.settings.password.PasswordUtils;
+import com.android.settings.safetycenter.SafetyCenterManagerWrapper;
import com.android.settingslib.Utils;
import com.android.settingslib.core.lifecycle.HideNonSystemOverlayMixin;
@@ -241,10 +248,21 @@ public class SettingsHomepageActivity extends FragmentActivity implements
if (isFinishing()) {
return;
}
+
+ if (ActivityEmbeddingUtils.isEmbeddingActivityEnabled(this)
+ && (intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0) {
+ initSplitPairRules();
+ }
+
// Launch the intent from deep link for large screen devices.
launchDeepLinkIntentToRight();
}
+ @VisibleForTesting
+ void initSplitPairRules() {
+ new ActivityEmbeddingRulesController(getApplicationContext()).initRules();
+ }
+
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
@@ -431,6 +449,40 @@ public class SettingsHomepageActivity extends FragmentActivity implements
finish();
return;
}
+
+ ActivityInfo targetActivityInfo = null;
+ try {
+ targetActivityInfo = getPackageManager().getActivityInfo(targetComponentName,
+ /* flags= */ 0);
+ } catch (PackageManager.NameNotFoundException e) {
+ Log.e(TAG, "Failed to get target ActivityInfo: " + e);
+ finish();
+ return;
+ }
+
+ int callingUid = -1;
+ try {
+ callingUid = ActivityManager.getService().getLaunchedFromUid(getActivityToken());
+ } catch (RemoteException re) {
+ Log.e(TAG, "Not able to get callingUid: " + re);
+ finish();
+ return;
+ }
+
+ if (!hasPrivilegedAccess(callingUid, targetActivityInfo)) {
+ if (!targetActivityInfo.exported) {
+ Log.e(TAG, "Target Activity is not exported");
+ finish();
+ return;
+ }
+
+ if (!isCallingAppPermitted(targetActivityInfo.permission)) {
+ Log.e(TAG, "Calling app must have the permission of deep link Activity");
+ finish();
+ return;
+ }
+ }
+
targetIntent.setComponent(targetComponentName);
// To prevent launchDeepLinkIntentToRight again for configuration change.
@@ -448,6 +500,19 @@ public class SettingsHomepageActivity extends FragmentActivity implements
targetIntent.setData(intent.getParcelableExtra(
SettingsHomepageActivity.EXTRA_SETTINGS_LARGE_SCREEN_DEEP_LINK_INTENT_DATA));
+ // Only allow FLAG_GRANT_READ/WRITE_URI_PERMISSION if calling app has the permission to
+ // access specified Uri.
+ int uriPermissionFlags = targetIntent.getFlags()
+ & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
+ if (targetIntent.getData() != null
+ && uriPermissionFlags != 0
+ && checkUriPermission(targetIntent.getData(), /* pid= */ -1, callingUid,
+ uriPermissionFlags) == PackageManager.PERMISSION_DENIED) {
+ Log.e(TAG, "Calling app must have the permission to access Uri and grant permission");
+ finish();
+ return;
+ }
+
// Set 2-pane pair rule for the deep link page.
ActivityEmbeddingRulesController.registerTwoPanePairRule(this,
new ComponentName(getApplicationContext(), getClass()),
@@ -472,6 +537,44 @@ public class SettingsHomepageActivity extends FragmentActivity implements
}
}
+ // Check if calling app has privileged access to launch Activity of activityInfo.
+ private boolean hasPrivilegedAccess(int callingUid, ActivityInfo activityInfo) {
+ if (TextUtils.equals(PasswordUtils.getCallingAppPackageName(getActivityToken()),
+ getPackageName())) {
+ return true;
+ }
+
+ int targetUid = -1;
+ try {
+ targetUid = getPackageManager().getApplicationInfo(activityInfo.packageName,
+ /* flags= */ 0).uid;
+ } catch (PackageManager.NameNotFoundException nnfe) {
+ Log.e(TAG, "Not able to get targetUid: " + nnfe);
+ return false;
+ }
+
+ // When activityInfo.exported is false, Activity still can be launched if applications have
+ // the same user ID.
+ if (UserHandle.isSameApp(callingUid, targetUid)) {
+ return true;
+ }
+
+ // When activityInfo.exported is false, Activity still can be launched if calling app has
+ // root or system privilege.
+ int callingAppId = UserHandle.getAppId(callingUid);
+ if (callingAppId == Process.ROOT_UID || callingAppId == Process.SYSTEM_UID) {
+ return true;
+ }
+
+ return false;
+ }
+
+ @VisibleForTesting
+ boolean isCallingAppPermitted(String permission) {
+ return TextUtils.isEmpty(permission) || PasswordUtils.isCallingAppPermitted(
+ this, getActivityToken(), permission);
+ }
+
private String getHighlightMenuKey() {
final Intent intent = getIntent();
if (intent != null && TextUtils.equals(intent.getAction(),
@@ -479,13 +582,30 @@ public class SettingsHomepageActivity extends FragmentActivity implements
final String menuKey = intent.getStringExtra(
EXTRA_SETTINGS_EMBEDDED_DEEP_LINK_HIGHLIGHT_MENU_KEY);
if (!TextUtils.isEmpty(menuKey)) {
- return menuKey;
+ return maybeRemapMenuKey(menuKey);
}
}
return getString(DEFAULT_HIGHLIGHT_MENU_KEY);
}
- private void reloadHighlightMenuKey() {
+ private String maybeRemapMenuKey(String menuKey) {
+ boolean isPrivacyOrSecurityMenuKey =
+ getString(R.string.menu_key_privacy).equals(menuKey)
+ || getString(R.string.menu_key_security).equals(menuKey);
+ boolean isSafetyCenterMenuKey = getString(R.string.menu_key_safety_center).equals(menuKey);
+
+ if (isPrivacyOrSecurityMenuKey && SafetyCenterManagerWrapper.get().isEnabled(this)) {
+ return getString(R.string.menu_key_safety_center);
+ }
+ if (isSafetyCenterMenuKey && !SafetyCenterManagerWrapper.get().isEnabled(this)) {
+ // We don't know if security or privacy, default to security as it is above.
+ return getString(R.string.menu_key_security);
+ }
+ return menuKey;
+ }
+
+ @VisibleForTesting
+ void reloadHighlightMenuKey() {
mMainFragment.getArguments().putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY,
getHighlightMenuKey());
mMainFragment.reloadHighlightMenuKey();
diff --git a/src/com/android/settings/homepage/TopLevelHighlightMixin.java b/src/com/android/settings/homepage/TopLevelHighlightMixin.java
index 4718443f8a4778e0581fe24040e6fef8d15d13b9..db099cbfb98f81a33c258c3e36de3a8786285fa8 100644
--- a/src/com/android/settings/homepage/TopLevelHighlightMixin.java
+++ b/src/com/android/settings/homepage/TopLevelHighlightMixin.java
@@ -114,9 +114,14 @@ public class TopLevelHighlightMixin implements Parcelable, DialogInterface.OnSho
}
Log.d(TAG, "onCreateAdapter, pref key: " + mCurrentKey);
+
+ // Remove the animator to avoid a RecyclerView crash.
+ RecyclerView recyclerView = topLevelSettings.getListView();
+ recyclerView.setItemAnimator(null);
+
mTopLevelAdapter = new HighlightableTopLevelPreferenceAdapter(
(SettingsHomepageActivity) topLevelSettings.getActivity(), preferenceScreen,
- topLevelSettings.getListView(), mCurrentKey, scrollNeeded);
+ recyclerView, mCurrentKey, scrollNeeded);
return mTopLevelAdapter;
}
diff --git a/src/com/android/settings/homepage/TopLevelSettings.java b/src/com/android/settings/homepage/TopLevelSettings.java
index 70530fc8cd33910bcc6ce9dde539407c5f84e592..8c122ef2ad6c1b22446a6162095af78c136dc82d 100644
--- a/src/com/android/settings/homepage/TopLevelSettings.java
+++ b/src/com/android/settings/homepage/TopLevelSettings.java
@@ -43,6 +43,7 @@ import com.android.settings.activityembedding.ActivityEmbeddingRulesController;
import com.android.settings.activityembedding.ActivityEmbeddingUtils;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.support.SupportPreferenceController;
import com.android.settings.widget.HomepagePreference;
@@ -157,6 +158,8 @@ public class TopLevelSettings extends DashboardFragment implements SplitLayoutLi
public void onStart() {
if (mFirstStarted) {
mFirstStarted = false;
+ FeatureFactory.getFactory(getContext()).getSearchFeatureProvider().sendPreIndexIntent(
+ getContext());
} else if (mIsEmbeddingActivityEnabled && isOnlyOneActivityInTask()
&& !SplitController.getInstance().isActivityEmbedded(getActivity())) {
// Set default highlight menu key for 1-pane homepage since it will show the placeholder
@@ -346,7 +349,9 @@ public class TopLevelSettings extends DashboardFragment implements SplitLayoutLi
}
private interface PreferenceJob {
- default void init() {}
+ default void init() {
+ }
+
void doForEach(Preference preference);
}
diff --git a/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProvider.java b/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProvider.java
index 067fcf90e00299328d2651772a80ae0d50c16240..81142c205698de231faa69e7243793eabef97fa1 100644
--- a/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProvider.java
+++ b/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProvider.java
@@ -50,12 +50,6 @@ public class SettingsContextualCardProvider extends ContextualCardProvider {
.setCardName(CustomSliceRegistry.LOW_STORAGE_SLICE_URI.toString())
.setCardCategory(ContextualCard.Category.IMPORTANT)
.build();
- final ContextualCard batteryFixCard =
- ContextualCard.newBuilder()
- .setSliceUri(CustomSliceRegistry.BATTERY_FIX_SLICE_URI.toString())
- .setCardName(CustomSliceRegistry.BATTERY_FIX_SLICE_URI.toString())
- .setCardCategory(ContextualCard.Category.IMPORTANT)
- .build();
final String contextualAdaptiveSleepSliceUri =
CustomSliceRegistry.CONTEXTUAL_ADAPTIVE_SLEEP_URI.toString();
final ContextualCard contextualAdaptiveSleepCard =
@@ -80,7 +74,6 @@ public class SettingsContextualCardProvider extends ContextualCardProvider {
.addCard(wifiCard)
.addCard(connectedDeviceCard)
.addCard(lowStorageCard)
- .addCard(batteryFixCard)
.addCard(contextualAdaptiveSleepCard)
.addCard(contextualFaceSettingsCard)
.addCard(darkThemeCard)
diff --git a/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSlice.java b/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSlice.java
deleted file mode 100644
index 33dcd4e79726e0d67c4af0a593db428bef5666b3..0000000000000000000000000000000000000000
--- a/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSlice.java
+++ /dev/null
@@ -1,258 +0,0 @@
-/*
- * 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.homepage.contextualcards.slices;
-
-import static android.content.Context.MODE_PRIVATE;
-
-import static com.android.settings.slices.CustomSliceRegistry.BATTERY_FIX_SLICE_URI;
-
-import android.app.PendingIntent;
-import android.app.settings.SettingsEnums;
-import android.content.Context;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.graphics.PorterDuff;
-import android.graphics.PorterDuffColorFilter;
-import android.graphics.drawable.Drawable;
-import android.net.Uri;
-import android.os.BatteryUsageStats;
-import android.util.ArrayMap;
-import android.view.View;
-
-import androidx.annotation.VisibleForTesting;
-import androidx.annotation.WorkerThread;
-import androidx.core.graphics.drawable.IconCompat;
-import androidx.slice.Slice;
-import androidx.slice.builders.ListBuilder;
-import androidx.slice.builders.ListBuilder.RowBuilder;
-import androidx.slice.builders.SliceAction;
-
-import com.android.settings.R;
-import com.android.settings.SubSettings;
-import com.android.settings.Utils;
-import com.android.settings.fuelgauge.batterytip.BatteryTipLoader;
-import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController;
-import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
-import com.android.settings.fuelgauge.batteryusage.BatteryUsageStatsLoader;
-import com.android.settings.fuelgauge.batteryusage.PowerUsageSummary;
-import com.android.settings.slices.CustomSliceable;
-import com.android.settings.slices.SliceBackgroundWorker;
-import com.android.settings.slices.SliceBuilderUtils;
-import com.android.settingslib.utils.ThreadUtils;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-
-public class BatteryFixSlice implements CustomSliceable {
-
- @VisibleForTesting
- static final String PREFS = "battery_fix_prefs";
- @VisibleForTesting
- static final String KEY_CURRENT_TIPS_TYPE = "current_tip_type";
- static final String KEY_CURRENT_TIPS_STATE = "current_tip_state";
-
- // A map tracking which BatteryTip and which state of that tip is not important.
- private static final Map> UNIMPORTANT_BATTERY_TIPS;
-
- static {
- UNIMPORTANT_BATTERY_TIPS = new ArrayMap<>();
- UNIMPORTANT_BATTERY_TIPS.put(BatteryTip.TipType.SUMMARY,
- Arrays.asList(BatteryTip.StateType.NEW, BatteryTip.StateType.HANDLED));
- UNIMPORTANT_BATTERY_TIPS.put(BatteryTip.TipType.HIGH_DEVICE_USAGE,
- Arrays.asList(BatteryTip.StateType.NEW, BatteryTip.StateType.HANDLED));
- UNIMPORTANT_BATTERY_TIPS.put(BatteryTip.TipType.BATTERY_SAVER,
- Arrays.asList(BatteryTip.StateType.HANDLED));
- }
-
- private static final String TAG = "BatteryFixSlice";
-
- private final Context mContext;
-
- public BatteryFixSlice(Context context) {
- mContext = context;
- }
-
- @Override
- public Uri getUri() {
- return BATTERY_FIX_SLICE_URI;
- }
-
- @Override
- public Slice getSlice() {
- final ListBuilder sliceBuilder =
- new ListBuilder(mContext, BATTERY_FIX_SLICE_URI, ListBuilder.INFINITY)
- .setAccentColor(COLOR_NOT_TINTED);
-
- if (!isBatteryTipAvailableFromCache(mContext)) {
- return buildBatteryGoodSlice(sliceBuilder, true /* isError */);
- }
-
- final SliceBackgroundWorker worker = SliceBackgroundWorker.getInstance(getUri());
- final List batteryTips = worker != null ? worker.getResults() : null;
-
- if (batteryTips == null) {
- // Because we need wait slice background worker return data
- return buildBatteryGoodSlice(sliceBuilder, false /* isError */);
- }
-
- for (BatteryTip batteryTip : batteryTips) {
- if (batteryTip.getState() == BatteryTip.StateType.INVISIBLE) {
- continue;
- }
- final Drawable drawable = mContext.getDrawable(batteryTip.getIconId());
- final int iconTintColorId = batteryTip.getIconTintColorId();
- if (iconTintColorId != View.NO_ID) {
- drawable.setColorFilter(new PorterDuffColorFilter(
- mContext.getResources().getColor(iconTintColorId),
- PorterDuff.Mode.SRC_IN));
- }
-
- final IconCompat icon = Utils.createIconWithDrawable(drawable);
- final SliceAction primaryAction = SliceAction.createDeeplink(getPrimaryAction(),
- icon,
- ListBuilder.ICON_IMAGE,
- batteryTip.getTitle(mContext));
- sliceBuilder.addRow(new RowBuilder()
- .setTitleItem(icon, ListBuilder.ICON_IMAGE)
- .setTitle(batteryTip.getTitle(mContext))
- .setSubtitle(batteryTip.getSummary(mContext))
- .setPrimaryAction(primaryAction));
- break;
- }
- return sliceBuilder.build();
- }
-
- @Override
- public Intent getIntent() {
- final String screenTitle = mContext.getText(R.string.power_usage_summary_title)
- .toString();
- final Uri contentUri = new Uri.Builder()
- .appendPath(BatteryTipPreferenceController.PREF_NAME).build();
-
- return SliceBuilderUtils.buildSearchResultPageIntent(mContext,
- PowerUsageSummary.class.getName(), BatteryTipPreferenceController.PREF_NAME,
- screenTitle,
- SettingsEnums.SLICE,
- this)
- .setClassName(mContext.getPackageName(), SubSettings.class.getName())
- .setData(contentUri);
- }
-
- @Override
- public int getSliceHighlightMenuRes() {
- return R.string.menu_key_battery;
- }
-
- @Override
- public void onNotifyChange(Intent intent) {
- }
-
- @Override
- public Class getBackgroundWorkerClass() {
- return BatteryTipWorker.class;
- }
-
- private PendingIntent getPrimaryAction() {
- final Intent intent = getIntent();
- return PendingIntent.getActivity(mContext, 0 /* requestCode */, intent,
- PendingIntent.FLAG_IMMUTABLE);
- }
-
- private Slice buildBatteryGoodSlice(ListBuilder sliceBuilder, boolean isError) {
- final IconCompat icon = IconCompat.createWithResource(mContext,
- R.drawable.ic_battery_status_good_24dp);
- final String title = mContext.getString(R.string.power_usage_summary_title);
- final SliceAction primaryAction = SliceAction.createDeeplink(getPrimaryAction(), icon,
- ListBuilder.ICON_IMAGE, title);
- sliceBuilder.addRow(new RowBuilder()
- .setTitleItem(icon, ListBuilder.ICON_IMAGE)
- .setTitle(title)
- .setPrimaryAction(primaryAction))
- .setIsError(isError);
- return sliceBuilder.build();
- }
-
- // TODO(b/114807643): we should find a better way to get current battery tip type quickly
- // Now we save battery tip type to shared preference when battery level changes
- public static void updateBatteryTipAvailabilityCache(Context context) {
- ThreadUtils.postOnBackgroundThread(() -> refreshBatteryTips(context));
- }
-
-
- @VisibleForTesting
- static boolean isBatteryTipAvailableFromCache(Context context) {
- final SharedPreferences prefs = context.getSharedPreferences(PREFS, MODE_PRIVATE);
-
- final int type = prefs.getInt(KEY_CURRENT_TIPS_TYPE, BatteryTip.TipType.SUMMARY);
- final int state = prefs.getInt(KEY_CURRENT_TIPS_STATE, BatteryTip.StateType.INVISIBLE);
- if (state == BatteryTip.StateType.INVISIBLE) {
- // State is INVISIBLE, We should not show anything.
- return false;
- }
- final boolean unimportant = UNIMPORTANT_BATTERY_TIPS.containsKey(type)
- && UNIMPORTANT_BATTERY_TIPS.get(type).contains(state);
- return !unimportant;
- }
-
- @WorkerThread
- @VisibleForTesting
- static List refreshBatteryTips(Context context) {
- final BatteryUsageStatsLoader statsLoader = new BatteryUsageStatsLoader(context,
- /* includeBatteryHistory */ false);
- final BatteryUsageStats batteryUsageStats = statsLoader.loadInBackground();
- final BatteryTipLoader loader = new BatteryTipLoader(context, batteryUsageStats);
- final List batteryTips = loader.loadInBackground();
- for (BatteryTip batteryTip : batteryTips) {
- if (batteryTip.getState() != BatteryTip.StateType.INVISIBLE) {
- context.getSharedPreferences(PREFS, MODE_PRIVATE)
- .edit()
- .putInt(KEY_CURRENT_TIPS_TYPE, batteryTip.getType())
- .putInt(KEY_CURRENT_TIPS_STATE, batteryTip.getState())
- .apply();
- break;
- }
- }
- return batteryTips;
- }
-
- public static class BatteryTipWorker extends SliceBackgroundWorker {
-
- private final Context mContext;
-
- public BatteryTipWorker(Context context, Uri uri) {
- super(context, uri);
- mContext = context;
- }
-
- @Override
- protected void onSlicePinned() {
- ThreadUtils.postOnBackgroundThread(() -> {
- final List batteryTips = refreshBatteryTips(mContext);
- updateResults(batteryTips);
- });
- }
-
- @Override
- protected void onSliceUnpinned() {
- }
-
- @Override
- public void close() {
- }
- }
-}
diff --git a/src/com/android/settings/media/MediaOutputIndicatorWorker.java b/src/com/android/settings/media/MediaOutputIndicatorWorker.java
index 09e06723b864a2c328442232d21d99d7cfb34de1..bf1e06e4e0c4c32df3c652b9d19b0354d303a20b 100644
--- a/src/com/android/settings/media/MediaOutputIndicatorWorker.java
+++ b/src/com/android/settings/media/MediaOutputIndicatorWorker.java
@@ -165,6 +165,13 @@ public class MediaOutputIndicatorWorker extends SliceBackgroundWorker implements
return mPackageName;
}
+ /** Check if this device supports LE Audio Broadcast feature */
+ public boolean isBroadcastSupported() {
+ LocalBluetoothLeBroadcast broadcast =
+ mLocalBluetoothManager.getProfileManager().getLeAudioBroadcastProfile();
+ return broadcast != null ? true : false;
+ }
+
public boolean isDeviceBroadcasting() {
LocalBluetoothLeBroadcast broadcast =
mLocalBluetoothManager.getProfileManager().getLeAudioBroadcastProfile();
diff --git a/src/com/android/settings/media/MediaOutputUtils.java b/src/com/android/settings/media/MediaOutputUtils.java
index 977c5178165468e87f23e8eac5f419974eaa5ec0..fcb2fb2b524964dbd6dcf4445ba37f9a976bcb38 100644
--- a/src/com/android/settings/media/MediaOutputUtils.java
+++ b/src/com/android/settings/media/MediaOutputUtils.java
@@ -64,7 +64,9 @@ public class MediaOutputUtils {
+ ", play back type : " + pi.getPlaybackType() + ", play back state : "
+ playbackState.getState());
}
- if (playbackState.getState() != PlaybackState.STATE_PLAYING) {
+ if (playbackState.getState() == PlaybackState.STATE_STOPPED
+ || playbackState.getState() == PlaybackState.STATE_NONE
+ || playbackState.getState() == PlaybackState.STATE_ERROR) {
// do nothing
continue;
}
diff --git a/src/com/android/settings/network/CarrierConfigChangedReceiver.java b/src/com/android/settings/network/CarrierConfigChangedReceiver.java
index 8a6d47d96fce07c681bc6f302e511195a04fbfe3..d9ff03efb6ac98fea98bb04d54b577b784e3efb5 100644
--- a/src/com/android/settings/network/CarrierConfigChangedReceiver.java
+++ b/src/com/android/settings/network/CarrierConfigChangedReceiver.java
@@ -32,9 +32,20 @@ public class CarrierConfigChangedReceiver extends BroadcastReceiver {
CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED;
private final CountDownLatch mLatch;
+ private final boolean mIsWaitingForValidSubId;
- public CarrierConfigChangedReceiver(CountDownLatch latch) {
+ /**
+ * This is the CarrierConfigChanged receiver. If it receives the carrier config changed, then it
+ * call the CountDownLatch.countDown().
+ * If the "isWaitingForValidSubId" is true, then the receiver skip the carrier config changed
+ * with the subId = -1. The receiver executes the countDown when the CarrierConfigChanged
+ * with valid subId.
+ * If the "isWaitingForValidSubId" is false, then the receiver executes the countDown when
+ * receiving any CarrierConfigChanged.
+ */
+ public CarrierConfigChangedReceiver(CountDownLatch latch, boolean isWaitingForValidSubId) {
mLatch = latch;
+ mIsWaitingForValidSubId = isWaitingForValidSubId;
}
public void registerOn(Context context) {
@@ -53,7 +64,8 @@ public class CarrierConfigChangedReceiver extends BroadcastReceiver {
}
private void checkSubscriptionIndex(Intent intent) {
- if (intent.hasExtra(CarrierConfigManager.EXTRA_SUBSCRIPTION_INDEX)) {
+ if (intent.hasExtra(CarrierConfigManager.EXTRA_SUBSCRIPTION_INDEX)
+ || !mIsWaitingForValidSubId) {
int subId = intent.getIntExtra(CarrierConfigManager.EXTRA_SUBSCRIPTION_INDEX, -1);
Log.i(TAG, "subId from config changed: " + subId);
mLatch.countDown();
diff --git a/src/com/android/settings/network/InternetResetHelper.java b/src/com/android/settings/network/InternetResetHelper.java
index 086ef1b1c5d2747718dcc11956910021dbd54be2..7920cca8f61bb171f4c3abcab63b2efaeaf4d2a4 100644
--- a/src/com/android/settings/network/InternetResetHelper.java
+++ b/src/com/android/settings/network/InternetResetHelper.java
@@ -21,14 +21,9 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.wifi.WifiManager;
-import android.os.HandlerThread;
-import android.os.Process;
-import android.text.TextUtils;
import android.util.Log;
-import androidx.annotation.UiThread;
import androidx.annotation.VisibleForTesting;
-import androidx.annotation.WorkerThread;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;
@@ -38,14 +33,14 @@ import androidx.preference.PreferenceCategory;
import com.android.settingslib.connectivity.ConnectivitySubsystemsRecoveryManager;
import com.android.settingslib.utils.HandlerInjector;
+import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
/**
* Helper class to restart connectivity for all requested subsystems.
*/
-public class InternetResetHelper implements LifecycleObserver,
- ConnectivitySubsystemsRecoveryManager.RecoveryStatusCallback {
+public class InternetResetHelper implements LifecycleObserver {
protected static final String TAG = "InternetResetHelper";
public static final long RESTART_TIMEOUT_MS = 15_000; // 15 seconds
@@ -61,41 +56,40 @@ public class InternetResetHelper implements LifecycleObserver,
protected final IntentFilter mWifiStateFilter;
protected final BroadcastReceiver mWifiStateReceiver = new BroadcastReceiver() {
@Override
- @WorkerThread
public void onReceive(Context context, Intent intent) {
- if (intent != null && TextUtils.equals(intent.getAction(),
- WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
- updateWifiStateChange();
- }
+ updateWifiStateChange();
}
};
- protected ConnectivitySubsystemsRecoveryManager mConnectivitySubsystemsRecoveryManager;
- protected HandlerThread mWorkerThread;
- protected boolean mIsRecoveryReady;
- protected boolean mIsWifiReady;
+ protected RecoveryWorker mRecoveryWorker;
+ protected boolean mIsWifiReady = true;
protected HandlerInjector mHandlerInjector;
- protected final Runnable mResumeRunnable = () -> {
- resumePreferences();
- };
protected final Runnable mTimeoutRunnable = () -> {
- mIsRecoveryReady = true;
+ Log.w(TAG, "Resume preferences due to connectivity subsystems recovery timed out.");
+ mRecoveryWorker.clearRecovering();
mIsWifiReady = true;
resumePreferences();
};
- public InternetResetHelper(Context context, Lifecycle lifecycle) {
+ public InternetResetHelper(Context context, Lifecycle lifecycle,
+ NetworkMobileProviderController mobileNetworkController,
+ Preference wifiTogglePreferences,
+ PreferenceCategory connectedWifiEntryPreferenceCategory,
+ PreferenceCategory firstWifiEntryPreferenceCategory,
+ PreferenceCategory wifiEntryPreferenceCategory,
+ Preference resettingPreference) {
mContext = context;
+ mMobileNetworkController = mobileNetworkController;
+ mWifiTogglePreferences = wifiTogglePreferences;
+ mWifiNetworkPreferences.add(connectedWifiEntryPreferenceCategory);
+ mWifiNetworkPreferences.add(firstWifiEntryPreferenceCategory);
+ mWifiNetworkPreferences.add(wifiEntryPreferenceCategory);
+ mResettingPreference = resettingPreference;
+
mHandlerInjector = new HandlerInjector(context.getMainThreadHandler());
mWifiManager = mContext.getSystemService(WifiManager.class);
mWifiStateFilter = new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION);
-
- mWorkerThread = new HandlerThread(TAG
- + "{" + Integer.toHexString(System.identityHashCode(this)) + "}",
- Process.THREAD_PRIORITY_BACKGROUND);
- mWorkerThread.start();
- mConnectivitySubsystemsRecoveryManager = new ConnectivitySubsystemsRecoveryManager(
- mContext, mWorkerThread.getThreadHandler());
+ mRecoveryWorker = RecoveryWorker.getInstance(mContext, this);
if (lifecycle != null) {
lifecycle.addObserver(this);
@@ -118,72 +112,18 @@ public class InternetResetHelper implements LifecycleObserver,
/** @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) */
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
public void onDestroy() {
- mHandlerInjector.removeCallbacks(mResumeRunnable);
mHandlerInjector.removeCallbacks(mTimeoutRunnable);
- mWorkerThread.quit();
- }
-
- @Override
- @WorkerThread
- public void onSubsystemRestartOperationBegin() {
- Log.d(TAG, "The connectivity subsystem is starting for recovery.");
- }
-
- @Override
- @WorkerThread
- public void onSubsystemRestartOperationEnd() {
- Log.d(TAG, "The connectivity subsystem is done for recovery.");
- if (!mIsRecoveryReady) {
- mIsRecoveryReady = true;
- mHandlerInjector.postDelayed(mResumeRunnable, 0 /* delayMillis */);
- }
}
@VisibleForTesting
- @WorkerThread
protected void updateWifiStateChange() {
if (!mIsWifiReady && mWifiManager.isWifiEnabled()) {
Log.d(TAG, "The Wi-Fi subsystem is done for recovery.");
mIsWifiReady = true;
- mHandlerInjector.postDelayed(mResumeRunnable, 0 /* delayMillis */);
+ resumePreferences();
}
}
- /**
- * Sets the resetting preference.
- */
- @UiThread
- public void setResettingPreference(Preference preference) {
- mResettingPreference = preference;
- }
-
- /**
- * Sets the mobile network controller.
- */
- @UiThread
- public void setMobileNetworkController(NetworkMobileProviderController controller) {
- mMobileNetworkController = controller;
- }
-
- /**
- * Sets the Wi-Fi toggle preference.
- */
- @UiThread
- public void setWifiTogglePreference(Preference preference) {
- mWifiTogglePreferences = preference;
- }
-
- /**
- * Adds the Wi-Fi network preference.
- */
- @UiThread
- public void addWifiNetworkPreference(PreferenceCategory preference) {
- if (preference != null) {
- mWifiNetworkPreferences.add(preference);
- }
- }
-
- @UiThread
protected void suspendPreferences() {
Log.d(TAG, "Suspend the subsystem preferences");
if (mMobileNetworkController != null) {
@@ -201,9 +141,9 @@ public class InternetResetHelper implements LifecycleObserver,
}
}
- @UiThread
protected void resumePreferences() {
- if (mIsRecoveryReady && mMobileNetworkController != null) {
+ boolean isRecoveryReady = !mRecoveryWorker.isRecovering();
+ if (isRecoveryReady && mMobileNetworkController != null) {
Log.d(TAG, "Resume the Mobile Network controller");
mMobileNetworkController.hidePreference(false /* hide */, true /* immediately */);
}
@@ -214,7 +154,7 @@ public class InternetResetHelper implements LifecycleObserver,
pref.setVisible(true);
}
}
- if (mIsRecoveryReady && mIsWifiReady) {
+ if (isRecoveryReady && mIsWifiReady) {
mHandlerInjector.removeCallbacks(mTimeoutRunnable);
if (mResettingPreference != null) {
Log.d(TAG, "Resume the Resetting preference");
@@ -223,21 +163,99 @@ public class InternetResetHelper implements LifecycleObserver,
}
}
- /**
- * Restart connectivity for all requested subsystems.
- */
- @UiThread
+ protected void showResettingAndSendTimeoutChecks() {
+ suspendPreferences();
+ mHandlerInjector.postDelayed(mTimeoutRunnable, RESTART_TIMEOUT_MS);
+ }
+
+ /** Restart connectivity for all requested subsystems. */
public void restart() {
- if (!mConnectivitySubsystemsRecoveryManager.isRecoveryAvailable()) {
+ if (!mRecoveryWorker.isRecoveryAvailable()) {
Log.e(TAG, "The connectivity subsystem is not available to restart.");
return;
}
-
- Log.d(TAG, "The connectivity subsystem is restarting for recovery.");
- suspendPreferences();
- mIsRecoveryReady = false;
+ showResettingAndSendTimeoutChecks();
mIsWifiReady = !mWifiManager.isWifiEnabled();
- mHandlerInjector.postDelayed(mTimeoutRunnable, RESTART_TIMEOUT_MS);
- mConnectivitySubsystemsRecoveryManager.triggerSubsystemRestart(null /* reason */, this);
+ mRecoveryWorker.triggerRestart();
+ }
+
+ /** Check if the connectivity subsystem is under recovering. */
+ public void checkRecovering() {
+ if (!mRecoveryWorker.isRecovering()) return;
+ mIsWifiReady = false;
+ showResettingAndSendTimeoutChecks();
+ }
+
+ /**
+ * This is a singleton class for ConnectivitySubsystemsRecoveryManager worker.
+ */
+ @VisibleForTesting
+ public static class RecoveryWorker implements
+ ConnectivitySubsystemsRecoveryManager.RecoveryStatusCallback {
+ private static final String TAG = "RecoveryWorker";
+ private static RecoveryWorker sInstance;
+ private static WeakReference sCallback;
+ private static ConnectivitySubsystemsRecoveryManager sRecoveryManager;
+ private static boolean sIsRecovering;
+
+ /**
+ * Create a singleton class for ConnectivitySubsystemsRecoveryManager.
+ *
+ * @param context The context to use for the content resolver.
+ * @param callback The callback of {@link InternetResetHelper} object.
+ * @return an instance of {@link RecoveryWorker} object.
+ */
+ public static RecoveryWorker getInstance(Context context, InternetResetHelper callback) {
+ sCallback = new WeakReference<>(callback);
+ if (sInstance != null) return sInstance;
+
+ sInstance = new RecoveryWorker();
+ Context appContext = context.getApplicationContext();
+ sRecoveryManager = new ConnectivitySubsystemsRecoveryManager(appContext,
+ appContext.getMainThreadHandler());
+ return sInstance;
+ }
+
+ /** Returns true, If the subsystem service is recovering. */
+ public boolean isRecovering() {
+ return sIsRecovering;
+ }
+
+ /** Clear the recovering flag. */
+ public void clearRecovering() {
+ sIsRecovering = false;
+ }
+
+ /** Returns true, If the subsystem service is recovery available. */
+ public boolean isRecoveryAvailable() {
+ return sRecoveryManager.isRecoveryAvailable();
+ }
+
+ /** Trigger connectivity recovery for all requested technologies. */
+ public boolean triggerRestart() {
+ if (!isRecoveryAvailable()) {
+ Log.e(TAG, "The connectivity subsystem is not available to restart.");
+ return false;
+ }
+ sIsRecovering = true;
+ sRecoveryManager.triggerSubsystemRestart(null /* reason */, sInstance);
+ Log.d(TAG, "The connectivity subsystem is restarting for recovery.");
+ return true;
+ }
+
+ @Override
+ public void onSubsystemRestartOperationBegin() {
+ Log.d(TAG, "The connectivity subsystem is starting for recovery.");
+ sIsRecovering = true;
+ }
+
+ @Override
+ public void onSubsystemRestartOperationEnd() {
+ Log.d(TAG, "The connectivity subsystem is done for recovery.");
+ sIsRecovering = false;
+ InternetResetHelper callback = sCallback.get();
+ if (callback == null) return;
+ callback.resumePreferences();
+ }
}
}
diff --git a/src/com/android/settings/network/NetworkProviderSettings.java b/src/com/android/settings/network/NetworkProviderSettings.java
index 1c480e057351b829c32084b30565dee63cd979c8..61a7d474a207f75e168ea5b848b53a981f875ebd 100644
--- a/src/com/android/settings/network/NetworkProviderSettings.java
+++ b/src/com/android/settings/network/NetworkProviderSettings.java
@@ -34,6 +34,7 @@ import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.PowerManager;
+import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
import android.telephony.TelephonyManager;
@@ -333,6 +334,8 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment
addConnectedEthernetNetworkController();
addWifiSwitchPreferenceController();
mWifiStatusMessagePreference = findPreference(PREF_KEY_WIFI_STATUS_MESSAGE);
+
+ checkConnectivityRecovering();
}
private void updateAirplaneModeMsgPreference(boolean visible) {
@@ -367,6 +370,17 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment
mWifiSwitchPreferenceController.displayPreference(getPreferenceScreen());
}
+ private void checkConnectivityRecovering() {
+ mInternetResetHelper = new InternetResetHelper(getContext(), getLifecycle(),
+ mNetworkMobileProviderController,
+ findPreference(WifiSwitchPreferenceController.KEY),
+ mConnectedWifiEntryPreferenceCategory,
+ mFirstWifiEntryPreferenceCategory,
+ mWifiEntryPreferenceCategory,
+ mResetInternetPreference);
+ mInternetResetHelper.checkRecovering();
+ }
+
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
@@ -598,10 +612,7 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment
return;
}
- if (mSelectedWifiEntry.isSaved() && mSelectedWifiEntry.getConnectedState()
- != WifiEntry.CONNECTED_STATE_CONNECTED) {
- menu.add(Menu.NONE, MENU_ID_MODIFY, 0 /* order */, R.string.wifi_modify);
- }
+ addModifyMenuIfSuitable(menu, mSelectedWifiEntry);
}
@VisibleForTesting
@@ -621,6 +632,14 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment
}
}
+ @VisibleForTesting
+ void addModifyMenuIfSuitable(ContextMenu menu, WifiEntry wifiEntry) {
+ if (mIsAdmin && wifiEntry.isSaved()
+ && wifiEntry.getConnectedState() != WifiEntry.CONNECTED_STATE_CONNECTED) {
+ menu.add(Menu.NONE, MENU_ID_MODIFY, 0 /* order */, R.string.wifi_modify);
+ }
+ }
+
private boolean canForgetNetwork() {
return mSelectedWifiEntry.canForget() && !WifiUtils.isNetworkLockedDown(getActivity(),
mSelectedWifiEntry.getWifiConfiguration());
@@ -643,6 +662,12 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment
() -> launchWifiDppConfiguratorActivity(mSelectedWifiEntry));
return true;
case MENU_ID_MODIFY:
+ if (!mIsAdmin) {
+ Log.e(TAG, "Can't modify Wi-Fi because the user isn't admin.");
+ EventLog.writeEvent(0x534e4554, "237672190", UserHandle.myUserId(),
+ "User isn't admin");
+ return true;
+ }
showDialog(mSelectedWifiEntry, WifiConfigUiBase2.MODE_MODIFY);
return true;
default:
@@ -1424,16 +1449,6 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment
}
private void fixConnectivity() {
- if (mInternetResetHelper == null) {
- mInternetResetHelper = new InternetResetHelper(getContext(), getLifecycle());
- mInternetResetHelper.setResettingPreference(mResetInternetPreference);
- mInternetResetHelper.setMobileNetworkController(mNetworkMobileProviderController);
- mInternetResetHelper.setWifiTogglePreference(
- findPreference(WifiSwitchPreferenceController.KEY));
- mInternetResetHelper.addWifiNetworkPreference(mConnectedWifiEntryPreferenceCategory);
- mInternetResetHelper.addWifiNetworkPreference(mFirstWifiEntryPreferenceCategory);
- mInternetResetHelper.addWifiNetworkPreference(mWifiEntryPreferenceCategory);
- }
mInternetResetHelper.restart();
}
diff --git a/src/com/android/settings/network/SubscriptionUtil.java b/src/com/android/settings/network/SubscriptionUtil.java
index 0bba86fafed385d246442f39d1072d8030dfb93d..ccfcfb0a752687a561b4453f508cc3107433eac9 100644
--- a/src/com/android/settings/network/SubscriptionUtil.java
+++ b/src/com/android/settings/network/SubscriptionUtil.java
@@ -86,6 +86,14 @@ public class SubscriptionUtil {
return subscriptions;
}
+ /**
+ * Check if SIM hardware is visible to the end user.
+ */
+ public static boolean isSimHardwareVisible(Context context) {
+ return context.getResources()
+ .getBoolean(R.bool.config_show_sim_info);
+ }
+
@VisibleForTesting
static boolean isInactiveInsertedPSim(UiccSlotInfo slotInfo) {
if (slotInfo == null) {
diff --git a/src/com/android/settings/network/UiccSlotUtil.java b/src/com/android/settings/network/UiccSlotUtil.java
index e5323d11b99a09eab474717476ca11a39185eb78..4c26995f3770dabb9aa37174ae5eff3b5b073831 100644
--- a/src/com/android/settings/network/UiccSlotUtil.java
+++ b/src/com/android/settings/network/UiccSlotUtil.java
@@ -28,7 +28,6 @@ import android.telephony.UiccSlotMapping;
import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
-import com.android.internal.telephony.uicc.UiccController;
import com.android.settingslib.utils.ThreadUtils;
import com.google.common.collect.ImmutableList;
@@ -141,7 +140,8 @@ public class UiccSlotUtil {
inactiveRemovableSlot,
/*removable sim's port Id*/ TelephonyManager.DEFAULT_PORT_INDEX,
excludedLogicalSlotIndex),
- context);
+ context,
+ /*isWaitingForValidSubId=*/ true);
}
/**
@@ -179,7 +179,8 @@ public class UiccSlotUtil {
performSwitchToSlot(telMgr,
prepareUiccSlotMappings(uiccSlotMappings, /*slot is not psim*/ false,
physicalSlotId, port, excludedLogicalSlotIndex),
- context);
+ context,
+ /*isWaitingForValidSubId=*/ false);
}
/**
@@ -231,7 +232,8 @@ public class UiccSlotUtil {
}
private static void performSwitchToSlot(TelephonyManager telMgr,
- Collection uiccSlotMappings, Context context)
+ Collection uiccSlotMappings, Context context,
+ boolean isWaitingForValidSubId)
throws UiccSlotsException {
CarrierConfigChangedReceiver receiver = null;
long waitingTimeMillis =
@@ -241,7 +243,7 @@ public class UiccSlotUtil {
DEFAULT_WAIT_AFTER_SWITCH_TIMEOUT_MILLIS);
try {
CountDownLatch latch = new CountDownLatch(1);
- receiver = new CarrierConfigChangedReceiver(latch);
+ receiver = new CarrierConfigChangedReceiver(latch, isWaitingForValidSubId);
receiver.registerOn(context);
telMgr.setSimSlotMapping(uiccSlotMappings);
latch.await(waitingTimeMillis, TimeUnit.MILLISECONDS);
@@ -270,6 +272,7 @@ public class UiccSlotUtil {
if (slotId == INVALID_PHYSICAL_SLOT_ID) {
for (int i = 0; i < slots.length; i++) {
if (slots[i].isRemovable()
+ && !slots[i].getIsEuicc()
&& !slots[i].getPorts().stream().findFirst().get().isActive()
&& slots[i].getCardStateInfo() != UiccSlotInfo.CARD_STATE_INFO_ERROR
&& slots[i].getCardStateInfo() != UiccSlotInfo.CARD_STATE_INFO_RESTRICTED) {
@@ -410,4 +413,29 @@ public class UiccSlotUtil {
.findFirst()
.orElse(INVALID_LOGICAL_SLOT_ID);
}
+
+ /**
+ * Return whether the removable psim is enabled.
+ *
+ * @param telMgr is a TelephonyManager.
+ * @return whether the removable psim is enabled.
+ */
+ public static boolean isRemovableSimEnabled(TelephonyManager telMgr) {
+ if (telMgr == null) {
+ return false;
+ }
+ ImmutableList slotInfos = UiccSlotUtil.getSlotInfos(telMgr);
+ boolean isRemovableSimEnabled =
+ slotInfos.stream()
+ .anyMatch(
+ slot -> slot != null
+ && slot.isRemovable()
+ && !slot.getIsEuicc()
+ && slot.getPorts().stream().anyMatch(
+ port -> port.isActive())
+ && slot.getCardStateInfo()
+ == UiccSlotInfo.CARD_STATE_INFO_PRESENT);
+ Log.i(TAG, "isRemovableSimEnabled: " + isRemovableSimEnabled);
+ return isRemovableSimEnabled;
+ }
}
diff --git a/src/com/android/settings/network/telephony/ToggleSubscriptionDialogActivity.java b/src/com/android/settings/network/telephony/ToggleSubscriptionDialogActivity.java
index a878cb3ebd3c837680fef8bf93a27d2b5c61eff1..6fa803d04330a1047850f55a78c3d5fb249adc34 100644
--- a/src/com/android/settings/network/telephony/ToggleSubscriptionDialogActivity.java
+++ b/src/com/android/settings/network/telephony/ToggleSubscriptionDialogActivity.java
@@ -24,7 +24,6 @@ import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.UiccCardInfo;
-import android.telephony.UiccSlotInfo;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
@@ -39,8 +38,6 @@ import com.android.settings.network.SwitchToRemovableSlotSidecar;
import com.android.settings.network.UiccSlotUtil;
import com.android.settings.sim.SimActivationNotifier;
-import com.google.common.collect.ImmutableList;
-
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@@ -586,18 +583,7 @@ public class ToggleSubscriptionDialogActivity extends SubscriptionActionDialogAc
}
private boolean isRemovableSimEnabled() {
- ImmutableList slotInfos = UiccSlotUtil.getSlotInfos(mTelMgr);
- boolean isRemovableSimEnabled =
- slotInfos.stream()
- .anyMatch(
- slot -> slot != null
- && slot.isRemovable()
- && slot.getPorts().stream().anyMatch(
- port -> port.isActive())
- && slot.getCardStateInfo()
- == UiccSlotInfo.CARD_STATE_INFO_PRESENT);
- Log.i(TAG, "isRemovableSimEnabled: " + isRemovableSimEnabled);
- return isRemovableSimEnabled;
+ return UiccSlotUtil.isRemovableSimEnabled(mTelMgr);
}
private boolean isMultipleEnabledProfilesSupported() {
diff --git a/src/com/android/settings/notification/MediaVolumePreferenceController.java b/src/com/android/settings/notification/MediaVolumePreferenceController.java
index 2466b7747a3ad5f89454a84cb3714c10797e4e93..443f748f7d9d3bf73f0322dd273f918f0375e5fe 100644
--- a/src/com/android/settings/notification/MediaVolumePreferenceController.java
+++ b/src/com/android/settings/notification/MediaVolumePreferenceController.java
@@ -93,7 +93,7 @@ public class MediaVolumePreferenceController extends VolumeSeekBarPreferenceCont
@VisibleForTesting
boolean isSupportEndItem() {
- return isConnectedBLEDevice();
+ return getWorker() != null && getWorker().isBroadcastSupported() && isConnectedBLEDevice();
}
private boolean isConnectedBLEDevice() {
@@ -124,7 +124,7 @@ public class MediaVolumePreferenceController extends VolumeSeekBarPreferenceCont
getWorker().getActiveLocalMediaController().getPackageName());
pi = PendingIntent.getBroadcast(context, 0 /* requestCode */, intent,
- PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE);
+ PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
} else {
final CachedBluetoothDevice bluetoothDevice =
((BluetoothMediaDevice) mMediaDevice).getCachedDevice();
@@ -141,7 +141,7 @@ public class MediaVolumePreferenceController extends VolumeSeekBarPreferenceCont
&& getWorker().getActiveLocalMediaController() != null);
pi = PendingIntent.getActivity(context, 0 /* requestCode */, intent,
- PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE);
+ PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
}
final IconCompat icon = getBroadcastIcon(context);
diff --git a/src/com/android/settings/notification/NotificationAssistantPreferenceController.java b/src/com/android/settings/notification/NotificationAssistantPreferenceController.java
index 2c02db9c32705d92a605ef909938ba6f97c0cdf9..ee36273d85c854c671f8bd2e25b77760af734cc4 100644
--- a/src/com/android/settings/notification/NotificationAssistantPreferenceController.java
+++ b/src/com/android/settings/notification/NotificationAssistantPreferenceController.java
@@ -141,7 +141,10 @@ public class NotificationAssistantPreferenceController extends TogglePreferenceC
@Override
public void updateState(Preference preference) {
super.updateState(preference);
- if (isNASSettingActivityAvailable()) {
+ if (mDefaultNASComponent == null) {
+ preference.setEnabled(false);
+ ((PrimarySwitchPreference) preference).setSwitchEnabled(false);
+ } else if (isNASSettingActivityAvailable()) {
preference.setIntent(mNASSettingIntent);
} else {
// Cannot find settings activity from the default NAS app
diff --git a/src/com/android/settings/notification/NotificationBackend.java b/src/com/android/settings/notification/NotificationBackend.java
index 150dbe0483d208bd64bf5892f7b48ecc32add162..68f5d081d115ff8cff55b2d954cf5c7cc748e570 100644
--- a/src/com/android/settings/notification/NotificationBackend.java
+++ b/src/com/android/settings/notification/NotificationBackend.java
@@ -126,6 +126,7 @@ public class NotificationBackend {
if (app.requestedPermissions == null || Arrays.stream(app.requestedPermissions)
.noneMatch(p -> p.equals(android.Manifest.permission.POST_NOTIFICATIONS))) {
row.lockedImportance = true;
+ row.permissionStateLocked = true;
}
}
}
@@ -684,6 +685,9 @@ public class NotificationBackend {
public boolean systemApp;
public boolean lockedImportance;
public boolean showBadge;
+ // For apps target T but have not but has not requested the permission
+ // we cannot change the permission state
+ public boolean permissionStateLocked;
public int bubblePreference = NotificationManager.BUBBLE_PREFERENCE_NONE;
public int userId;
public int blockedChannelCount;
diff --git a/src/com/android/settings/notification/NotificationVolumePreferenceController.java b/src/com/android/settings/notification/NotificationVolumePreferenceController.java
index 0fe0d6282e8986f134abcc7ca988a479321461fc..112debca64782e487c016d6ae7348ba542d820ea 100644
--- a/src/com/android/settings/notification/NotificationVolumePreferenceController.java
+++ b/src/com/android/settings/notification/NotificationVolumePreferenceController.java
@@ -16,26 +16,139 @@
package com.android.settings.notification;
+import android.app.ActivityThread;
+import android.app.INotificationManager;
+import android.app.NotificationManager;
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
import android.media.AudioManager;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
+import android.os.ServiceManager;
+import android.os.Vibrator;
+import android.provider.DeviceConfig;
+import android.service.notification.NotificationListenerService;
import android.text.TextUtils;
+import android.util.Log;
+import androidx.lifecycle.OnLifecycleEvent;
+import androidx.preference.PreferenceScreen;
+
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.config.sysui.SystemUiDeviceConfigFlags;
import com.android.settings.R;
import com.android.settings.Utils;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+
+import java.util.Objects;
+import java.util.Set;
-public class NotificationVolumePreferenceController extends
- RingVolumePreferenceController {
+/**
+ * Update notification volume icon in Settings in response to user adjusting volume.
+ */
+public class NotificationVolumePreferenceController extends VolumeSeekBarPreferenceController {
+ private static final String TAG = "NotificationVolumePreferenceController";
private static final String KEY_NOTIFICATION_VOLUME = "notification_volume";
+ private static final boolean CONFIG_DEFAULT_VAL = false;
+ private boolean mSeparateNotification;
+
+ private Vibrator mVibrator;
+ private int mRingerMode = AudioManager.RINGER_MODE_NORMAL;
+ private ComponentName mSuppressor;
+ private final RingReceiver mReceiver = new RingReceiver();
+ private final H mHandler = new H();
+ private INotificationManager mNoMan;
+ private int mMuteIcon;
+ private final int mNormalIconId = R.drawable.ic_notifications;
+ private final int mVibrateIconId = R.drawable.ic_volume_ringer_vibrate;
+ private final int mSilentIconId = R.drawable.ic_notifications_off_24dp;
public NotificationVolumePreferenceController(Context context) {
- super(context, KEY_NOTIFICATION_VOLUME);
+ this(context, KEY_NOTIFICATION_VOLUME);
+ }
+
+ public NotificationVolumePreferenceController(Context context, String key) {
+ super(context, key);
+
+ mVibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
+ if (mVibrator != null && !mVibrator.hasVibrator()) {
+ mVibrator = null;
+ }
+
+ updateRingerMode();
+ }
+
+ /**
+ * Allow for notification slider to be enabled in the scenario where the config switches on
+ * while settings page is already on the screen by always configuring the preference, even if it
+ * is currently inactive.
+ */
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ if (mPreference == null) {
+ setupVolPreference(screen);
+ }
+ mSeparateNotification = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SYSTEMUI,
+ SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, CONFIG_DEFAULT_VAL);
+ if (mPreference != null) {
+ mPreference.setVisible(getAvailabilityStatus() == AVAILABLE);
+ }
+ updateEffectsSuppressor();
+ updatePreferenceIconAndSliderState();
+ }
+
+ /**
+ * Only display the notification slider when the corresponding device config flag is set
+ */
+ private void onDeviceConfigChange(DeviceConfig.Properties properties) {
+ Set changeSet = properties.getKeyset();
+
+ if (changeSet.contains(SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION)) {
+ boolean newVal = properties.getBoolean(
+ SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, CONFIG_DEFAULT_VAL);
+ if (newVal != mSeparateNotification) {
+ mSeparateNotification = newVal;
+ // manually hiding the preference because being unavailable does not do the job
+ if (mPreference != null) {
+ mPreference.setVisible(getAvailabilityStatus() == AVAILABLE);
+ }
+ }
+ }
+ }
+
+
+ @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
+ @Override
+ public void onResume() {
+ super.onResume();
+ mReceiver.register(true);
+ DeviceConfig.addOnPropertiesChangedListener(DeviceConfig.NAMESPACE_SYSTEMUI,
+ ActivityThread.currentApplication().getMainExecutor(),
+ this::onDeviceConfigChange);
+ }
+
+ @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
+ @Override
+ public void onPause() {
+ super.onPause();
+ mReceiver.register(false);
+ DeviceConfig.removeOnPropertiesChangedListener(this::onDeviceConfigChange);
}
@Override
public int getAvailabilityStatus() {
+ boolean separateNotification = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SYSTEMUI,
+ SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, false);
+
return mContext.getResources().getBoolean(R.bool.config_show_notification_volume)
- && !Utils.isVoiceCapable(mContext) && !mHelper.isSingleVolume()
+ && !mHelper.isSingleVolume()
+ && (separateNotification || !Utils.isVoiceCapable(mContext))
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
@@ -54,6 +167,11 @@ public class NotificationVolumePreferenceController extends
return KEY_NOTIFICATION_VOLUME;
}
+ @Override
+ public boolean useDynamicSliceSummary() {
+ return true;
+ }
+
@Override
public int getAudioStream() {
return AudioManager.STREAM_NOTIFICATION;
@@ -61,7 +179,141 @@ public class NotificationVolumePreferenceController extends
@Override
public int getMuteIcon() {
- return R.drawable.ic_notifications_off_24dp;
+ return mMuteIcon;
+ }
+
+ private void updateRingerMode() {
+ final int ringerMode = mHelper.getRingerModeInternal();
+ if (mRingerMode == ringerMode) return;
+ mRingerMode = ringerMode;
+ updatePreferenceIconAndSliderState();
+ }
+
+ private void updateEffectsSuppressor() {
+ final ComponentName suppressor = NotificationManager.from(mContext).getEffectsSuppressor();
+ if (Objects.equals(suppressor, mSuppressor)) return;
+
+ if (mNoMan == null) {
+ mNoMan = INotificationManager.Stub.asInterface(
+ ServiceManager.getService(Context.NOTIFICATION_SERVICE));
+ }
+
+ final int hints;
+ try {
+ hints = mNoMan.getHintsFromListenerNoToken();
+ } catch (android.os.RemoteException exception) {
+ Log.w(TAG, "updateEffectsSuppressor: " + exception.getLocalizedMessage());
+ return;
+ }
+
+ if (hintsMatch(hints)) {
+
+ mSuppressor = suppressor;
+ if (mPreference != null) {
+ final String text = SuppressorHelper.getSuppressionText(mContext, suppressor);
+ mPreference.setSuppressionText(text);
+ }
+ }
+ }
+
+ @VisibleForTesting
+ boolean hintsMatch(int hints) {
+ boolean allEffectsDisabled =
+ (hints & NotificationListenerService.HINT_HOST_DISABLE_EFFECTS) != 0;
+ boolean notificationEffectsDisabled =
+ (hints & NotificationListenerService.HINT_HOST_DISABLE_NOTIFICATION_EFFECTS) != 0;
+
+ return allEffectsDisabled || notificationEffectsDisabled;
+ }
+
+ private void updatePreferenceIconAndSliderState() {
+ if (mPreference != null) {
+ if (mVibrator != null && mRingerMode == AudioManager.RINGER_MODE_VIBRATE) {
+ mMuteIcon = mVibrateIconId;
+ mPreference.showIcon(mVibrateIconId);
+ mPreference.setEnabled(false);
+
+ } else if (mRingerMode == AudioManager.RINGER_MODE_SILENT
+ || mVibrator == null && mRingerMode == AudioManager.RINGER_MODE_VIBRATE) {
+ mMuteIcon = mSilentIconId;
+ mPreference.showIcon(mSilentIconId);
+ mPreference.setEnabled(false);
+ } else { // ringmode normal: could be that we are still silent
+ mPreference.setEnabled(true);
+ if (mHelper.getStreamVolume(AudioManager.STREAM_NOTIFICATION) == 0) {
+ // ring is in normal, but notification is in silent
+ mMuteIcon = mSilentIconId;
+ mPreference.showIcon(mSilentIconId);
+ } else {
+ mPreference.showIcon(mNormalIconId);
+ }
+ }
+ }
+ }
+
+ private final class H extends Handler {
+ private static final int UPDATE_EFFECTS_SUPPRESSOR = 1;
+ private static final int UPDATE_RINGER_MODE = 2;
+ private static final int NOTIFICATION_VOLUME_CHANGED = 3;
+
+ private H() {
+ super(Looper.getMainLooper());
+ }
+
+ @Override
+ public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case UPDATE_EFFECTS_SUPPRESSOR:
+ updateEffectsSuppressor();
+ break;
+ case UPDATE_RINGER_MODE:
+ updateRingerMode();
+ break;
+ case NOTIFICATION_VOLUME_CHANGED:
+ updatePreferenceIconAndSliderState();
+ break;
+ }
+ }
+ }
+
+ /**
+ * For notification volume icon to be accurate, we need to listen to volume change as well.
+ * That is because the icon can change from mute/vibrate to normal without ringer mode changing.
+ */
+ private class RingReceiver extends BroadcastReceiver {
+ private boolean mRegistered;
+
+ public void register(boolean register) {
+ if (mRegistered == register) return;
+ if (register) {
+ final IntentFilter filter = new IntentFilter();
+ filter.addAction(NotificationManager.ACTION_EFFECTS_SUPPRESSOR_CHANGED);
+ filter.addAction(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION);
+ filter.addAction(AudioManager.VOLUME_CHANGED_ACTION);
+ mContext.registerReceiver(this, filter);
+ } else {
+ mContext.unregisterReceiver(this);
+ }
+ mRegistered = register;
+ }
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ final String action = intent.getAction();
+ if (NotificationManager.ACTION_EFFECTS_SUPPRESSOR_CHANGED.equals(action)) {
+ mHandler.sendEmptyMessage(H.UPDATE_EFFECTS_SUPPRESSOR);
+ } else if (AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION.equals(action)) {
+ mHandler.sendEmptyMessage(H.UPDATE_RINGER_MODE);
+ } else if (AudioManager.VOLUME_CHANGED_ACTION.equals(action)) {
+ int streamType = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, -1);
+ if (streamType == AudioManager.STREAM_NOTIFICATION) {
+ int streamValue = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE,
+ -1);
+ mHandler.obtainMessage(H.NOTIFICATION_VOLUME_CHANGED, streamValue, 0)
+ .sendToTarget();
+ }
+ }
+ }
}
}
diff --git a/src/com/android/settings/notification/RedactionInterstitial.java b/src/com/android/settings/notification/RedactionInterstitial.java
index f243250a6113297e81a4363600874df848064248..d6fdaf81c95f4673c35c6a74e3968fe6b7319703 100644
--- a/src/com/android/settings/notification/RedactionInterstitial.java
+++ b/src/com/android/settings/notification/RedactionInterstitial.java
@@ -189,13 +189,16 @@ public class RedactionInterstitial extends SettingsActivity {
}
private void loadFromSettings() {
+ final boolean showUnRedactedDefault = getContext().getResources().getBoolean(
+ R.bool.default_allow_sensitive_lockscreen_content);
final boolean managedProfile = UserManager.get(getContext()).isManagedProfile(mUserId);
// Hiding all notifications is device-wide setting, managed profiles can only set
// whether their notifications are show in full or redacted.
final boolean showNotifications = managedProfile || Settings.Secure.getIntForUser(
getContentResolver(), LOCK_SCREEN_SHOW_NOTIFICATIONS, 0, mUserId) != 0;
final boolean showUnredacted = Settings.Secure.getIntForUser(
- getContentResolver(), LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1, mUserId) != 0;
+ getContentResolver(), LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS,
+ showUnRedactedDefault ? 1 : 0, mUserId) != 0;
int checkedButtonId = R.id.hide_all;
if (showNotifications) {
diff --git a/src/com/android/settings/notification/RingVolumePreferenceController.java b/src/com/android/settings/notification/RingVolumePreferenceController.java
index 5e7d067a8ad89d001062e2d61ed2e15159995c50..7fdb1e161417aab265ad6b423a8d6fa3c174a672 100644
--- a/src/com/android/settings/notification/RingVolumePreferenceController.java
+++ b/src/com/android/settings/notification/RingVolumePreferenceController.java
@@ -16,6 +16,8 @@
package com.android.settings.notification;
+import android.app.ActivityThread;
+import android.app.INotificationManager;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
@@ -26,30 +28,56 @@ import android.media.AudioManager;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
+import android.os.ServiceManager;
import android.os.Vibrator;
+import android.provider.DeviceConfig;
+import android.service.notification.NotificationListenerService;
import android.text.TextUtils;
+import android.util.Log;
import androidx.lifecycle.OnLifecycleEvent;
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.config.sysui.SystemUiDeviceConfigFlags;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settingslib.core.lifecycle.Lifecycle;
import java.util.Objects;
+import java.util.Set;
+/**
+ * This slider can represent both ring and notification, if the corresponding streams are aliased,
+ * and only ring if the streams are not aliased.
+ */
public class RingVolumePreferenceController extends VolumeSeekBarPreferenceController {
- private static final String TAG = "RingVolumeController";
+ private static final String TAG = "RingVolumePreferenceController";
private static final String KEY_RING_VOLUME = "ring_volume";
private Vibrator mVibrator;
- private int mRingerMode = -1;
+ private int mRingerMode = AudioManager.RINGER_MODE_NORMAL;
private ComponentName mSuppressor;
private final RingReceiver mReceiver = new RingReceiver();
private final H mHandler = new H();
private int mMuteIcon;
+ private int mNormalIconId;
+ @VisibleForTesting
+ int mVibrateIconId;
+ @VisibleForTesting
+ int mSilentIconId;
+
+ @VisibleForTesting
+ int mTitleId;
+
+ private boolean mSeparateNotification;
+
+ private INotificationManager mNoMan;
+
+ private static final boolean CONFIG_DEFAULT_VAL = false;
+
public RingVolumePreferenceController(Context context) {
this(context, KEY_RING_VOLUME);
}
@@ -60,16 +88,69 @@ public class RingVolumePreferenceController extends VolumeSeekBarPreferenceContr
if (mVibrator != null && !mVibrator.hasVibrator()) {
mVibrator = null;
}
+ mSeparateNotification = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SYSTEMUI,
+ SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, CONFIG_DEFAULT_VAL);
+ loadPreferenceIconResources(mSeparateNotification);
updateRingerMode();
}
+ private void loadPreferenceIconResources(boolean separateNotification) {
+ if (separateNotification) {
+ mTitleId = R.string.separate_ring_volume_option_title;
+ mNormalIconId = R.drawable.ic_ring_volume;
+ mSilentIconId = R.drawable.ic_ring_volume_off;
+ } else {
+ mTitleId = R.string.ring_volume_option_title;
+ mNormalIconId = R.drawable.ic_notifications;
+ mSilentIconId = R.drawable.ic_notifications_off_24dp;
+ }
+ // todo: set a distinct vibrate icon for ring vs notification
+ mVibrateIconId = R.drawable.ic_volume_ringer_vibrate;
+ }
+
+ /**
+ * As the responsibility of this slider changes, so should its title & icon
+ */
+ public void onDeviceConfigChange(DeviceConfig.Properties properties) {
+ Set changeSet = properties.getKeyset();
+ if (changeSet.contains(SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION)) {
+ boolean valueUpdated = readSeparateNotificationVolumeConfig();
+ if (valueUpdated) {
+ updateEffectsSuppressor();
+ selectPreferenceIconState();
+ setPreferenceTitle();
+ }
+ }
+ }
+
+ /**
+ * side effect: updates the cached value of the config, and also the icon
+ * @return has the config changed?
+ */
+ private boolean readSeparateNotificationVolumeConfig() {
+ boolean newVal = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SYSTEMUI,
+ SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, CONFIG_DEFAULT_VAL);
+
+ boolean valueUpdated = newVal != mSeparateNotification;
+ if (valueUpdated) {
+ mSeparateNotification = newVal;
+ loadPreferenceIconResources(newVal);
+ }
+
+ return valueUpdated;
+ }
+
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
@Override
public void onResume() {
super.onResume();
mReceiver.register(true);
+ readSeparateNotificationVolumeConfig();
+ DeviceConfig.addOnPropertiesChangedListener(DeviceConfig.NAMESPACE_SYSTEMUI,
+ ActivityThread.currentApplication().getMainExecutor(), this::onDeviceConfigChange);
updateEffectsSuppressor();
- updatePreferenceIcon();
+ selectPreferenceIconState();
+ setPreferenceTitle();
}
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
@@ -77,6 +158,7 @@ public class RingVolumePreferenceController extends VolumeSeekBarPreferenceContr
public void onPause() {
super.onPause();
mReceiver.register(false);
+ DeviceConfig.removeOnPropertiesChangedListener(this::onDeviceConfigChange);
}
@Override
@@ -115,38 +197,85 @@ public class RingVolumePreferenceController extends VolumeSeekBarPreferenceContr
return mMuteIcon;
}
- private void updateRingerMode() {
+ @VisibleForTesting
+ void updateRingerMode() {
final int ringerMode = mHelper.getRingerModeInternal();
if (mRingerMode == ringerMode) return;
mRingerMode = ringerMode;
- updatePreferenceIcon();
+ selectPreferenceIconState();
}
private void updateEffectsSuppressor() {
final ComponentName suppressor = NotificationManager.from(mContext).getEffectsSuppressor();
if (Objects.equals(suppressor, mSuppressor)) return;
- mSuppressor = suppressor;
- if (mPreference != null) {
- final String text = SuppressorHelper.getSuppressionText(mContext, suppressor);
- mPreference.setSuppressionText(text);
+
+ if (mNoMan == null) {
+ mNoMan = INotificationManager.Stub.asInterface(
+ ServiceManager.getService(Context.NOTIFICATION_SERVICE));
}
- updatePreferenceIcon();
+
+ final int hints;
+ try {
+ hints = mNoMan.getHintsFromListenerNoToken();
+ } catch (android.os.RemoteException ex) {
+ Log.w(TAG, "updateEffectsSuppressor: " + ex.getMessage());
+ return;
+ }
+
+ if (hintsMatch(hints, DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SYSTEMUI,
+ SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, false))) {
+ mSuppressor = suppressor;
+ if (mPreference != null) {
+ final String text = SuppressorHelper.getSuppressionText(mContext, suppressor);
+ mPreference.setSuppressionText(text);
+ }
+ }
+ }
+
+ @VisibleForTesting
+ boolean hintsMatch(int hints, boolean notificationSeparated) {
+ return (hints & NotificationListenerService.HINT_HOST_DISABLE_CALL_EFFECTS) != 0
+ || (hints & NotificationListenerService.HINT_HOST_DISABLE_EFFECTS) != 0
+ || ((hints & NotificationListenerService.HINT_HOST_DISABLE_NOTIFICATION_EFFECTS)
+ != 0 && !notificationSeparated);
}
- private void updatePreferenceIcon() {
+ @VisibleForTesting
+ void setPreference(VolumeSeekBarPreference volumeSeekBarPreference) {
+ mPreference = volumeSeekBarPreference;
+ }
+
+ @VisibleForTesting
+ void setVibrator(Vibrator vibrator) {
+ mVibrator = vibrator;
+ }
+
+ private void selectPreferenceIconState() {
if (mPreference != null) {
- if (mRingerMode == AudioManager.RINGER_MODE_VIBRATE) {
- mMuteIcon = R.drawable.ic_volume_ringer_vibrate;
- mPreference.showIcon(R.drawable.ic_volume_ringer_vibrate);
- } else if (mRingerMode == AudioManager.RINGER_MODE_SILENT) {
- mMuteIcon = R.drawable.ic_notifications_off_24dp;
- mPreference.showIcon(R.drawable.ic_notifications_off_24dp);
+ if (mRingerMode == AudioManager.RINGER_MODE_NORMAL) {
+ mPreference.showIcon(mNormalIconId);
} else {
- mPreference.showIcon(R.drawable.ic_notifications);
+ if (mRingerMode == AudioManager.RINGER_MODE_VIBRATE && mVibrator != null) {
+ mMuteIcon = mVibrateIconId;
+ } else {
+ mMuteIcon = mSilentIconId;
+ }
+ mPreference.showIcon(mMuteIcon);
}
}
}
+ /**
+ * This slider can represent both ring and notification, or only ring.
+ * Note: This cannot be used in the constructor, as the reference to preference object would
+ * still be null.
+ */
+ private void setPreferenceTitle() {
+ if (mPreference != null) {
+ mPreference.setTitle(mTitleId);
+ }
+ }
+
private final class H extends Handler {
private static final int UPDATE_EFFECTS_SUPPRESSOR = 1;
private static final int UPDATE_RINGER_MODE = 2;
diff --git a/src/com/android/settings/notification/ShowOnLockScreenNotificationPreferenceController.java b/src/com/android/settings/notification/ShowOnLockScreenNotificationPreferenceController.java
index f7dc3913775c6c8a4d64101f908cc9866cff1477..1addd8220dbbc8767ad4c9694626580ab30e7013 100644
--- a/src/com/android/settings/notification/ShowOnLockScreenNotificationPreferenceController.java
+++ b/src/com/android/settings/notification/ShowOnLockScreenNotificationPreferenceController.java
@@ -23,6 +23,9 @@ import android.content.Context;
import android.os.UserHandle;
import android.provider.Settings;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+
import com.android.settings.R;
import com.android.settings.RestrictedListPreference;
import com.android.settings.core.PreferenceControllerMixin;
@@ -34,9 +37,6 @@ import com.google.common.annotations.VisibleForTesting;
import java.util.ArrayList;
-import androidx.preference.Preference;
-import androidx.preference.PreferenceScreen;
-
public class ShowOnLockScreenNotificationPreferenceController extends AbstractPreferenceController
implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
@@ -157,6 +157,6 @@ public class ShowOnLockScreenNotificationPreferenceController extends AbstractPr
private boolean getLockscreenSilentNotificationsEnabled() {
return Settings.Secure.getInt(mContext.getContentResolver(),
- Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 1) != 0;
+ Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 0) != 0;
}
}
diff --git a/src/com/android/settings/notification/VibrateIconPreferenceController.java b/src/com/android/settings/notification/VibrateIconPreferenceController.java
index 25d232641316f37087bcac91db8c3dff88037f56..d772b47d59e1cb868ccfe4f1b9bae83f4b56cc07 100644
--- a/src/com/android/settings/notification/VibrateIconPreferenceController.java
+++ b/src/com/android/settings/notification/VibrateIconPreferenceController.java
@@ -19,6 +19,7 @@ package com.android.settings.notification;
import static com.android.settings.notification.SettingPref.TYPE_SECURE;
import android.content.Context;
+import android.os.Vibrator;
import android.provider.Settings.Secure;
import com.android.settings.SettingsPreferenceFragment;
@@ -27,16 +28,18 @@ import com.android.settingslib.core.lifecycle.Lifecycle;
public class VibrateIconPreferenceController extends SettingPrefController {
private static final String KEY_VIBRATE_ICON = "vibrate_icon";
+ private final boolean mHasVibrator;
public VibrateIconPreferenceController(Context context, SettingsPreferenceFragment parent,
Lifecycle lifecycle) {
super(context, parent, lifecycle);
+ mHasVibrator = context.getSystemService(Vibrator.class).hasVibrator();
mPreference = new SettingPref(
TYPE_SECURE, KEY_VIBRATE_ICON, Secure.STATUS_BAR_SHOW_VIBRATE_ICON, 0 /*default off*/);
}
@Override
public boolean isAvailable() {
- return true;
+ return mHasVibrator;
}
}
diff --git a/src/com/android/settings/notification/VolumeSeekBarPreferenceController.java b/src/com/android/settings/notification/VolumeSeekBarPreferenceController.java
index d1701599c34f34937481160301b90e025f081967..0414565721ebba1fdc52c8c5decddd66dd3cd289 100644
--- a/src/com/android/settings/notification/VolumeSeekBarPreferenceController.java
+++ b/src/com/android/settings/notification/VolumeSeekBarPreferenceController.java
@@ -55,13 +55,17 @@ public abstract class VolumeSeekBarPreferenceController extends
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
if (isAvailable()) {
- mPreference = screen.findPreference(getPreferenceKey());
- mPreference.setCallback(mVolumePreferenceCallback);
- mPreference.setStream(getAudioStream());
- mPreference.setMuteIcon(getMuteIcon());
+ setupVolPreference(screen);
}
}
+ protected void setupVolPreference(PreferenceScreen screen) {
+ mPreference = screen.findPreference(getPreferenceKey());
+ mPreference.setCallback(mVolumePreferenceCallback);
+ mPreference.setStream(getAudioStream());
+ mPreference.setMuteIcon(getMuteIcon());
+ }
+
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
public void onResume() {
if (mPreference != null) {
diff --git a/src/com/android/settings/notification/app/ConversationNotificationSettings.java b/src/com/android/settings/notification/app/ConversationNotificationSettings.java
index ec9c65f51ad5ae22710ed153a9cd9bc6cc74cdd5..b452309f84cffda570182362272d8493e3f4e8bb 100644
--- a/src/com/android/settings/notification/app/ConversationNotificationSettings.java
+++ b/src/com/android/settings/notification/app/ConversationNotificationSettings.java
@@ -83,6 +83,7 @@ public class ConversationNotificationSettings extends NotificationSettings {
protected List createPreferenceControllers(Context context) {
mControllers = new ArrayList<>();
mControllers.add(new ConversationHeaderPreferenceController(context, this));
+ mControllers.add(new BlockPreferenceController(context, mDependentFieldListener, mBackend));
mControllers.add(new ConversationPriorityPreferenceController(
context, mBackend, mDependentFieldListener));
mControllers.add(new HighImportancePreferenceController(
diff --git a/src/com/android/settings/notification/app/NotificationsOffPreferenceController.java b/src/com/android/settings/notification/app/NotificationsOffPreferenceController.java
index 0c7cd2361e20c5df0dc6e76eaebe651172714bf4..04e3f0e311b35db34a972939b395c3c08331b7e3 100644
--- a/src/com/android/settings/notification/app/NotificationsOffPreferenceController.java
+++ b/src/com/android/settings/notification/app/NotificationsOffPreferenceController.java
@@ -62,6 +62,8 @@ public class NotificationsOffPreferenceController extends NotificationPreference
preference.setTitle(R.string.channel_notifications_off_desc);
} else if (mChannelGroup != null) {
preference.setTitle(R.string.channel_group_notifications_off_desc);
+ } else if (mAppRow.permissionStateLocked) {
+ preference.setTitle(R.string.app_notifications_not_send_desc);
} else {
preference.setTitle(R.string.app_notifications_off_desc);
}
diff --git a/src/com/android/settings/notification/history/NotificationHistoryActivity.java b/src/com/android/settings/notification/history/NotificationHistoryActivity.java
index 4fecfc9b72220677942a12fd2e0c5c751afca2e7..1f83cc728963f47e07330a419633c9d9b7a8befb 100644
--- a/src/com/android/settings/notification/history/NotificationHistoryActivity.java
+++ b/src/com/android/settings/notification/history/NotificationHistoryActivity.java
@@ -73,6 +73,10 @@ import java.util.concurrent.TimeUnit;
public class NotificationHistoryActivity extends CollapsingToolbarBaseActivity {
private static String TAG = "NotifHistory";
+ // MAX_RECENT_DISMISS_ITEM_COUNT needs to be less or equals than
+ // R.integer.config_notificationServiceArchiveSize, which is the Number of notifications kept
+ // in the notification service historical archive
+ private static final int MAX_RECENT_DISMISS_ITEM_COUNT = 50;
private ViewGroup mHistoryOn;
private ViewGroup mHistoryOff;
@@ -388,7 +392,8 @@ public class NotificationHistoryActivity extends CollapsingToolbarBaseActivity {
snoozed = getSnoozedNotifications();
dismissed = mNm.getHistoricalNotificationsWithAttribution(
NotificationHistoryActivity.this.getPackageName(),
- NotificationHistoryActivity.this.getAttributionTag(), 6, false);
+ NotificationHistoryActivity.this.getAttributionTag(),
+ MAX_RECENT_DISMISS_ITEM_COUNT, false);
} catch (SecurityException | RemoteException e) {
Log.d(TAG, "OnPaused called while trying to retrieve notifications");
}
diff --git a/src/com/android/settings/notification/zen/ZenRulePreference.java b/src/com/android/settings/notification/zen/ZenRulePreference.java
index f90183a93ffb4b0cd05885028885c243c9416c24..205aef9d1a9f25593861aa93b6bfbcb94733e49d 100644
--- a/src/com/android/settings/notification/zen/ZenRulePreference.java
+++ b/src/com/android/settings/notification/zen/ZenRulePreference.java
@@ -22,8 +22,10 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.ComponentInfo;
import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
import android.service.notification.ZenModeConfig;
import android.service.notification.ZenModeConfig.ScheduleInfo;
+import android.util.Log;
import androidx.fragment.app.Fragment;
import androidx.preference.Preference;
@@ -34,9 +36,11 @@ import com.android.settings.utils.ZenServiceListing;
import com.android.settingslib.PrimarySwitchPreference;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
+import java.util.List;
import java.util.Map;
public class ZenRulePreference extends PrimarySwitchPreference {
+ private static final String TAG = "ZenRulePreference";
private static final ManagedServiceSettings.Config CONFIG =
ZenModeAutomationSettings.getConditionProviderConfig();
final String mId;
@@ -121,8 +125,14 @@ public class ZenRulePreference extends PrimarySwitchPreference {
getSettingsActivity(mPm, rule, si);
mIntent = AbstractZenModeAutomaticRulePreferenceController.getRuleIntent(action,
settingsActivity, mId);
- if (mIntent.resolveActivity(mPm) == null) {
+ // If the intent's activity for this rule doesn't exist or resolve to anything, disable the
+ // preference and rule.
+ List results = mPm.queryIntentActivities(
+ mIntent, PackageManager.ResolveInfoFlags.of(0));
+ if (mIntent.resolveActivity(mPm) == null || results.size() == 0) {
+ Log.w(TAG, "intent for zen rule invalid: " + mIntent);
mIntent = null;
+ setEnabled(false);
}
setKey(mId);
}
diff --git a/src/com/android/settings/notification/zen/ZenRuleSelectionDialog.java b/src/com/android/settings/notification/zen/ZenRuleSelectionDialog.java
index b159a015d6ebe195acb2dc572218919a2bb7cd47..71df0144d68252252782fb4d1db95fa1f4d5cd0d 100644
--- a/src/com/android/settings/notification/zen/ZenRuleSelectionDialog.java
+++ b/src/com/android/settings/notification/zen/ZenRuleSelectionDialog.java
@@ -21,9 +21,11 @@ import android.app.NotificationManager;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.ComponentInfo;
import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
@@ -45,6 +47,7 @@ import com.android.settings.utils.ZenServiceListing;
import java.lang.ref.WeakReference;
import java.text.Collator;
import java.util.Comparator;
+import java.util.List;
import java.util.Set;
import java.util.TreeSet;
@@ -113,6 +116,14 @@ public class ZenRuleSelectionDialog extends InstrumentedDialogFragment {
}
}
+ // Returns whether the rule's configuration activity exists and is valid.
+ private boolean isRuleActivityValid(final ZenRuleInfo ri) {
+ Intent intent = new Intent().setComponent(ri.configurationActivity);
+ List results = mPm.queryIntentActivities(
+ intent, PackageManager.ResolveInfoFlags.of(0));
+ return intent.resolveActivity(mPm) != null && results.size() > 0;
+ }
+
private void bindType(final ZenRuleInfo ri) {
try {
ApplicationInfo info = mPm.getApplicationInfo(ri.packageName, 0);
@@ -122,6 +133,11 @@ public class ZenRuleSelectionDialog extends InstrumentedDialogFragment {
ImageView iconView = v.findViewById(R.id.icon);
((TextView) v.findViewById(R.id.title)).setText(ri.title);
if (!ri.isSystem) {
+ // Omit rule if the externally provided rule activity is not valid.
+ if (!isRuleActivityValid(ri)) {
+ Log.w(TAG, "rule configuration activity invalid: " + ri.configurationActivity);
+ return;
+ }
LoadIconTask task = new LoadIconTask(iconView);
task.execute(info);
diff --git a/src/com/android/settings/overlay/FeatureFactory.java b/src/com/android/settings/overlay/FeatureFactory.java
index c59b385459908b019b14b972b7ff840a71d2e232..aff7197e2748c9f617f513efae1c91244482fffc 100644
--- a/src/com/android/settings/overlay/FeatureFactory.java
+++ b/src/com/android/settings/overlay/FeatureFactory.java
@@ -45,7 +45,6 @@ import com.android.settings.security.SecurityFeatureProvider;
import com.android.settings.security.SecuritySettingsFeatureProvider;
import com.android.settings.slices.SlicesFeatureProvider;
import com.android.settings.users.UserFeatureProvider;
-import com.android.settings.vpn2.AdvancedVpnFeatureProvider;
import com.android.settings.wifi.WifiTrackerLibProvider;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
@@ -178,11 +177,6 @@ public abstract class FeatureFactory {
*/
public abstract AccessibilityMetricsFeatureProvider getAccessibilityMetricsFeatureProvider();
- /**
- * Retrieves implementation for advanced vpn feature.
- */
- public abstract AdvancedVpnFeatureProvider getAdvancedVpnFeatureProvider();
-
public static final class FactoryNotFoundException extends RuntimeException {
public FactoryNotFoundException(Throwable throwable) {
super("Unable to create factory. Did you misconfigure Proguard?", throwable);
diff --git a/src/com/android/settings/overlay/FeatureFactoryImpl.java b/src/com/android/settings/overlay/FeatureFactoryImpl.java
index 593b8666c0232bd20d30b0935fe5c87a3e51a55d..89f74de82332f6d84121cef188d254adad39c00e 100644
--- a/src/com/android/settings/overlay/FeatureFactoryImpl.java
+++ b/src/com/android/settings/overlay/FeatureFactoryImpl.java
@@ -71,8 +71,6 @@ import com.android.settings.slices.SlicesFeatureProvider;
import com.android.settings.slices.SlicesFeatureProviderImpl;
import com.android.settings.users.UserFeatureProvider;
import com.android.settings.users.UserFeatureProviderImpl;
-import com.android.settings.vpn2.AdvancedVpnFeatureProvider;
-import com.android.settings.vpn2.AdvancedVpnFeatureProviderImpl;
import com.android.settings.wifi.WifiTrackerLibProvider;
import com.android.settings.wifi.WifiTrackerLibProviderImpl;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
@@ -108,7 +106,6 @@ public class FeatureFactoryImpl extends FeatureFactory {
private SecuritySettingsFeatureProvider mSecuritySettingsFeatureProvider;
private AccessibilitySearchFeatureProvider mAccessibilitySearchFeatureProvider;
private AccessibilityMetricsFeatureProvider mAccessibilityMetricsFeatureProvider;
- private AdvancedVpnFeatureProvider mAdvancedVpnFeatureProvider;
@Override
public SupportFeatureProvider getSupportFeatureProvider(Context context) {
@@ -337,12 +334,4 @@ public class FeatureFactoryImpl extends FeatureFactory {
}
return mAccessibilityMetricsFeatureProvider;
}
-
- @Override
- public AdvancedVpnFeatureProvider getAdvancedVpnFeatureProvider() {
- if (mAdvancedVpnFeatureProvider == null) {
- mAdvancedVpnFeatureProvider = new AdvancedVpnFeatureProviderImpl();
- }
- return mAdvancedVpnFeatureProvider;
- }
}
diff --git a/src/com/android/settings/overlay/SurveyFeatureProvider.java b/src/com/android/settings/overlay/SurveyFeatureProvider.java
index 44ee525060e47f08f87b68a57c021244291a5f1f..ce5be981282fc32e16132984dfe2928961e20fce 100644
--- a/src/com/android/settings/overlay/SurveyFeatureProvider.java
+++ b/src/com/android/settings/overlay/SurveyFeatureProvider.java
@@ -26,14 +26,15 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager;
* An interface for classes wishing to provide the ability to serve surveys to implement.
*/
public interface SurveyFeatureProvider {
-
/**
* Downloads a survey asynchronously to shared preferences to be served at a later date.
*
* @param activity A valid context.
* @param surveyId A unique Id representing a survey to download.
- * @param data a text blob to be attached to the survey results.
+ * @param data a text blob to be attached to the survey results.
+ * @deprecated This is not used after T.
*/
+ @Deprecated
void downloadSurvey(Activity activity, String surveyId, @Nullable String data);
/**
@@ -42,17 +43,21 @@ public interface SurveyFeatureProvider {
* @param activity The host activity to show the survey in.
* @param surveyId A unique Id representing a survey to download.
* @return A boolean indicating if a survey was shown or not.
+ * @deprecated This is not used after T.
*/
+ @Deprecated
boolean showSurveyIfAvailable(Activity activity, String surveyId);
/**
* A helper method to get the surveyId. Implementers should create a mapping of
* keys to surveyIds and provide them via this function.
*
- * @param context A valid context.
+ * @param context A valid context.
* @param simpleKey The simple name of the key to get the surveyId for.
* @return The unique Id as a string or null on error.
+ * @deprecated This is not used after T.
*/
+ @Deprecated
String getSurveyId(Context context, String simpleKey);
/**
@@ -60,28 +65,36 @@ public interface SurveyFeatureProvider {
* unix timestamp) for the remaining survey should it exist and be ready to show. Returns -1 if
* no valid survey exists after removing the potentially expired one.
*
- * @param context the calling context.
+ * @param context the calling context.
* @param surveyId the site ID.
* @return the unix timestamp for the available survey for the given {@coe siteId} or -1 if
* there is none available.
+ * @deprecated This is not used after T.
*/
+ @Deprecated
long getSurveyExpirationDate(Context context, String surveyId);
/**
* Registers an activity to show surveys/prompts as soon as they are downloaded. The receiver
* should be unregistered prior to destroying the activity to avoid undefined behavior by
* calling {@link #unregisterReceiver(Activity, BroadcastReceiver)}.
+ *
* @param activity The activity that should show surveys once they are downloaded.
* @return the broadcast receiver listening for survey downloads. Must be unregistered before
* leaving the activity.
+ * @deprecated This is not used after T.
*/
+ @Deprecated
BroadcastReceiver createAndRegisterReceiver(Activity activity);
/**
* Unregisters the broadcast receiver for this activity. Should only be called once per activity
* after a call to {@link #createAndRegisterReceiver(Activity)}.
+ *
* @param activity The activity that was used to register the BroadcastReceiver.
+ * @deprecated This is not used after T.
*/
+ @Deprecated
static void unregisterReceiver(Activity activity, BroadcastReceiver receiver) {
if (activity == null) {
throw new IllegalStateException("Cannot unregister receiver if activity is null");
@@ -89,4 +102,11 @@ public interface SurveyFeatureProvider {
LocalBroadcastManager.getInstance(activity).unregisterReceiver(receiver);
}
+
+ /**
+ * Send the visited activity to the place where it will trigger a survey if possible.
+ *
+ * @param simpleKey The simple name of the key to get the surveyId for.
+ */
+ void sendActivityIfAvailable(String simpleKey);
}
diff --git a/src/com/android/settings/panel/PanelFragment.java b/src/com/android/settings/panel/PanelFragment.java
index 04ae3116176e1cd2ff946242d5bafeccecbdeaf7..5bc0cc8d636009cd70d9a25a1044131675aad5dd 100644
--- a/src/com/android/settings/panel/PanelFragment.java
+++ b/src/com/android/settings/panel/PanelFragment.java
@@ -60,6 +60,7 @@ import com.android.settingslib.utils.ThreadUtils;
import com.google.android.setupdesign.DividerItemDecoration;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
@@ -213,6 +214,8 @@ public class PanelFragment extends Fragment {
// Make the panel layout gone here, to avoid janky animation when updating from old panel.
// We will make it visible once the panel is ready to load.
mPanelSlices.setVisibility(View.GONE);
+ // Remove the animator to avoid a RecyclerView crash.
+ mPanelSlices.setItemAnimator(null);
final Bundle arguments = getArguments();
final String callingPackageName =
@@ -339,8 +342,13 @@ public class PanelFragment extends Fragment {
mSliceLiveData.put(uri, sliceLiveData);
sliceLiveData.observe(getViewLifecycleOwner(), slice -> {
- // If the Slice has already loaded, do nothing.
+
+ // If the Slice has already loaded, refresh list with slice data.
if (mPanelSlicesLoaderCountdownLatch.isSliceLoaded(uri)) {
+ if (mAdapter != null) {
+ int itemIndex = (new ArrayList<>(mSliceLiveData.keySet())).indexOf(uri);
+ mAdapter.notifyItemChanged(itemIndex);
+ }
return;
}
diff --git a/src/com/android/settings/panel/PanelSlicesAdapter.java b/src/com/android/settings/panel/PanelSlicesAdapter.java
index 9f5ffe97fa5fcbde0b5ae0f0da1d400819263f7b..d72836677876006b230f1874776722d2c9f3b7b2 100644
--- a/src/com/android/settings/panel/PanelSlicesAdapter.java
+++ b/src/com/android/settings/panel/PanelSlicesAdapter.java
@@ -54,7 +54,7 @@ public class PanelSlicesAdapter
* Maximum number of slices allowed on the panel view.
*/
@VisibleForTesting
- static final int MAX_NUM_OF_SLICES = 6;
+ static final int MAX_NUM_OF_SLICES = 7;
private final List> mSliceLiveData;
private final int mMetricsCategory;
@@ -84,7 +84,7 @@ public class PanelSlicesAdapter
@Override
public void onBindViewHolder(@NonNull SliceRowViewHolder sliceRowViewHolder, int position) {
- sliceRowViewHolder.onBind(mSliceLiveData.get(position), position);
+ sliceRowViewHolder.onBind(mSliceLiveData.get(position).getValue());
}
/**
@@ -132,15 +132,14 @@ public class PanelSlicesAdapter
/**
* Called when the view is displayed.
*/
- public void onBind(LiveData sliceLiveData, int position) {
- sliceLiveData.observe(mPanelFragment.getViewLifecycleOwner(), sliceView);
-
- // Do not show the divider above media devices switcher slice per request
- final Slice slice = sliceLiveData.getValue();
-
+ public void onBind(Slice slice) {
// Hides slice which reports with error hint or not contain any slice sub-item.
if (slice == null || !isValidSlice(slice)) {
sliceView.setVisibility(View.GONE);
+ return;
+ } else {
+ sliceView.setSlice(slice);
+ sliceView.setVisibility(View.VISIBLE);
}
// Add divider for the end icon
@@ -154,7 +153,7 @@ public class PanelSlicesAdapter
.action(0 /* attribution */,
SettingsEnums.ACTION_PANEL_INTERACTION,
mMetricsCategory,
- sliceLiveData.getValue().getUri().getLastPathSegment()
+ slice.getUri().getLastPathSegment()
/* log key */,
eventInfo.actionType /* value */);
})
diff --git a/src/com/android/settings/print/PrintServiceSettingsFragment.java b/src/com/android/settings/print/PrintServiceSettingsFragment.java
index eb7ab80e69fe574015c2b6fe22f70e24250a4ba1..39b5ab9e97873400ce2e71998f6680fccce4a42f 100644
--- a/src/com/android/settings/print/PrintServiceSettingsFragment.java
+++ b/src/com/android/settings/print/PrintServiceSettingsFragment.java
@@ -368,6 +368,7 @@ public class PrintServiceSettingsFragment extends SettingsPreferenceFragment
MenuItem searchItem = menu.findItem(R.id.print_menu_item_search);
if (mServiceEnabled && mPrintersAdapter.getUnfilteredCount() > 0) {
mSearchView = (SearchView) searchItem.getActionView();
+ mSearchView.setMaxWidth(Integer.MAX_VALUE);
mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
diff --git a/src/com/android/settings/search/SearchFeatureProvider.java b/src/com/android/settings/search/SearchFeatureProvider.java
index 1785361d3b289904923a21c4b4befec14df713a1..b14a4d7fbf5ecff316a5f580fbc34c7056ae0be6 100644
--- a/src/com/android/settings/search/SearchFeatureProvider.java
+++ b/src/com/android/settings/search/SearchFeatureProvider.java
@@ -71,6 +71,12 @@ public interface SearchFeatureProvider {
return context.getString(R.string.config_settingsintelligence_package_name);
}
+ /**
+ * Send the pre-index intent.
+ */
+ default void sendPreIndexIntent(Context context){
+ }
+
/**
* Initializes the search toolbar.
*/
diff --git a/src/com/android/settings/sim/SimDialogActivity.java b/src/com/android/settings/sim/SimDialogActivity.java
index 9c4f8f18915c460864f27b4d6c0df765ee5b174a..464ba9b4a51874696027a2f4b06c2f385cf1a14a 100644
--- a/src/com/android/settings/sim/SimDialogActivity.java
+++ b/src/com/android/settings/sim/SimDialogActivity.java
@@ -35,6 +35,7 @@ import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import com.android.settings.R;
+import com.android.settings.network.SubscriptionUtil;
import com.android.settings.network.telephony.SubscriptionActionDialogActivity;
import java.util.List;
@@ -65,6 +66,11 @@ public class SimDialogActivity extends FragmentActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ if (!SubscriptionUtil.isSimHardwareVisible(this)) {
+ Log.d(TAG, "Not support on device without SIM.");
+ finish();
+ return;
+ }
SimDialogProhibitService.supportDismiss(this);
getWindow().addSystemFlags(
diff --git a/src/com/android/settings/sim/SimSelectNotification.java b/src/com/android/settings/sim/SimSelectNotification.java
index 9d3f860a01481a08f8519a26c7aa0def2b25f89d..9b235cea93130431dace9c6a75e3c5b18136df1d 100644
--- a/src/com/android/settings/sim/SimSelectNotification.java
+++ b/src/com/android/settings/sim/SimSelectNotification.java
@@ -77,6 +77,10 @@ public class SimSelectNotification extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
+ if (!SubscriptionUtil.isSimHardwareVisible(context)) {
+ Log.w(TAG, "Received unexpected intent with null action.");
+ return;
+ }
String action = intent.getAction();
if (action == null) {
diff --git a/src/com/android/settings/sim/smartForwarding/SmartForwardingActivity.java b/src/com/android/settings/sim/smartForwarding/SmartForwardingActivity.java
index 217801e5a1761f40391ccb539748327caa67aeeb..070e65a1d56a61c5cb31f833c285db0c2687ecc5 100644
--- a/src/com/android/settings/sim/smartForwarding/SmartForwardingActivity.java
+++ b/src/com/android/settings/sim/smartForwarding/SmartForwardingActivity.java
@@ -38,6 +38,7 @@ import androidx.core.content.ContextCompat;
import com.android.settings.R;
import com.android.settings.core.SettingsBaseActivity;
+import com.android.settings.network.SubscriptionUtil;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
@@ -48,6 +49,7 @@ import com.google.common.util.concurrent.MoreExecutors;
import java.util.concurrent.Executors;
public class SmartForwardingActivity extends SettingsBaseActivity {
+ static final String LOG_TAG = SmartForwardingActivity.class.toString();
final ListeningExecutorService service =
MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor());
@@ -55,6 +57,12 @@ public class SmartForwardingActivity extends SettingsBaseActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ if (!SubscriptionUtil.isSimHardwareVisible(this)) {
+ Log.d(LOG_TAG, "Not support on device without SIM.");
+ finish();
+ return;
+ }
+
final Toolbar toolbar = findViewById(R.id.action_bar);
toolbar.setVisibility(View.VISIBLE);
setActionBar(toolbar);
@@ -166,4 +174,4 @@ public class SmartForwardingActivity extends SettingsBaseActivity {
.create();
mDialog.show();
}
-}
\ No newline at end of file
+}
diff --git a/src/com/android/settings/slices/CustomSliceRegistry.java b/src/com/android/settings/slices/CustomSliceRegistry.java
index d1b169c297604976322fb2ce33172fcb65d07b4b..c49d6224859d3031d74db4dbb66eae4b49ad0fbd 100644
--- a/src/com/android/settings/slices/CustomSliceRegistry.java
+++ b/src/com/android/settings/slices/CustomSliceRegistry.java
@@ -29,8 +29,6 @@ import androidx.annotation.VisibleForTesting;
import com.android.settings.display.AlwaysOnDisplaySlice;
import com.android.settings.display.ScreenTimeoutPreferenceController;
import com.android.settings.flashlight.FlashlightSlice;
-import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController;
-import com.android.settings.homepage.contextualcards.slices.BatteryFixSlice;
import com.android.settings.homepage.contextualcards.slices.BluetoothDevicesSlice;
import com.android.settings.homepage.contextualcards.slices.ContextualAdaptiveSleepSlice;
import com.android.settings.homepage.contextualcards.slices.DarkThemeSlice;
@@ -64,16 +62,6 @@ public class CustomSliceRegistry {
.appendPath(ScreenTimeoutPreferenceController.PREF_NAME)
.build();
- /**
- * Uri for Battery Fix Slice.
- */
- public static final Uri BATTERY_FIX_SLICE_URI = new Uri.Builder()
- .scheme(ContentResolver.SCHEME_CONTENT)
- .authority(SettingsSliceProvider.SLICE_AUTHORITY)
- .appendEncodedPath(SettingsSlicesContract.PATH_SETTING_INTENT)
- .appendPath(BatteryTipPreferenceController.PREF_NAME)
- .build();
-
/**
* Backing Uri for the Bluetooth Slice.
*/
@@ -217,6 +205,16 @@ public class CustomSliceRegistry {
.appendPath("ring_volume")
.build();
+ /**
+ * Full {@link Uri} for the Notification volume Slice.
+ */
+ public static final Uri VOLUME_NOTIFICATION_URI = new Uri.Builder()
+ .scheme(ContentResolver.SCHEME_CONTENT)
+ .authority(SettingsSliceProvider.SLICE_AUTHORITY)
+ .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
+ .appendPath("notification_volume")
+ .build();
+
/**
* Full {@link Uri} for the all volume Slices.
*/
@@ -321,7 +319,6 @@ public class CustomSliceRegistry {
static {
sUriToSlice = new ArrayMap<>();
- sUriToSlice.put(BATTERY_FIX_SLICE_URI, BatteryFixSlice.class);
sUriToSlice.put(BLUETOOTH_DEVICES_SLICE_URI, BluetoothDevicesSlice.class);
sUriToSlice.put(CONTEXTUAL_ADAPTIVE_SLEEP_URI, ContextualAdaptiveSleepSlice.class);
sUriToSlice.put(CONTEXTUAL_WIFI_SLICE_URI, ContextualWifiSlice.class);
diff --git a/src/com/android/settings/sound/AudioSwitchPreferenceController.java b/src/com/android/settings/sound/AudioSwitchPreferenceController.java
index 5b70d16a7a74e16b4c1f67aadbd5637f6c211423..6475257b29cbd1c6a1cd5250ae57470340fdcf0a 100644
--- a/src/com/android/settings/sound/AudioSwitchPreferenceController.java
+++ b/src/com/android/settings/sound/AudioSwitchPreferenceController.java
@@ -45,6 +45,7 @@ import com.android.settingslib.bluetooth.BluetoothCallback;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.HeadsetProfile;
import com.android.settingslib.bluetooth.HearingAidProfile;
+import com.android.settingslib.bluetooth.LeAudioProfile;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
@@ -52,6 +53,7 @@ import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
@@ -214,6 +216,41 @@ public abstract class AudioSwitchPreferenceController extends BasePreferenceCont
return a2dpProfile.getConnectedDevices();
}
+ /**
+ * Get LE Audio profile connected devices
+ */
+ protected List getConnectedLeAudioDevices() {
+ final List connectedDevices = new ArrayList<>();
+ final LeAudioProfile leAudioProfile = mProfileManager.getLeAudioProfile();
+ if (leAudioProfile == null) {
+ Log.d(TAG, "LeAudioProfile is null");
+ return connectedDevices;
+ }
+ final List devices = leAudioProfile.getConnectedDevices();
+ for (BluetoothDevice device : devices) {
+ if (device.isConnected() && isDeviceInCachedList(device)) {
+ connectedDevices.add(device);
+ }
+ }
+ return connectedDevices;
+ }
+
+ /**
+ * Confirm if the device exists in the cached devices list. If return true, it means
+ * the device is main device in the LE Audio device group. Otherwise, the device is the member
+ * device in the group.
+ */
+ protected boolean isDeviceInCachedList(BluetoothDevice device) {
+ Collection cachedDevices =
+ mLocalBluetoothManager.getCachedDeviceManager().getCachedDevicesCopy();
+ for (CachedBluetoothDevice cachedDevice : cachedDevices) {
+ if (cachedDevice.getDevice().equals(device)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
/**
* get hearing aid profile connected device, exclude other devices with same hiSyncId.
*/
@@ -259,6 +296,24 @@ public abstract class AudioSwitchPreferenceController extends BasePreferenceCont
return null;
}
+ /**
+ * Find active LE Audio device
+ */
+ protected BluetoothDevice findActiveLeAudioDevice() {
+ final LeAudioProfile leAudioProfile = mProfileManager.getLeAudioProfile();
+
+ if (leAudioProfile != null) {
+ List activeDevices = leAudioProfile.getActiveDevices();
+ for (BluetoothDevice leAudioDevice : activeDevices) {
+ if (leAudioDevice != null) {
+ return leAudioDevice;
+ }
+ }
+ }
+ Log.d(TAG, "There is no LE audio profile or no active LE audio device");
+ return null;
+ }
+
/**
* Find the active device from the corresponding profile.
*
diff --git a/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceController.java b/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceController.java
index 15f47cf25934abf68f5eac657974b6e3ddfbe417..35cc65fafe707346721692d2e1afd2666c1e14cc 100644
--- a/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceController.java
+++ b/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceController.java
@@ -103,6 +103,7 @@ public class HandsFreeProfileOutputPreferenceController extends AudioSwitchPrefe
mConnectedDevices.clear();
mConnectedDevices.addAll(getConnectedHfpDevices());
mConnectedDevices.addAll(getConnectedHearingAidDevices());
+ mConnectedDevices.addAll(getConnectedLeAudioDevices());
final int numDevices = mConnectedDevices.size();
if (numDevices == 0) {
@@ -181,12 +182,22 @@ public class HandsFreeProfileOutputPreferenceController extends AudioSwitchPrefe
@Override
public BluetoothDevice findActiveDevice() {
- BluetoothDevice activeDevice = findActiveHearingAidDevice();
+ BluetoothDevice haActiveDevice = findActiveHearingAidDevice();
+ BluetoothDevice leAudioActiveDevice = findActiveLeAudioDevice();
final HeadsetProfile headsetProfile = mProfileManager.getHeadsetProfile();
- if (activeDevice == null && headsetProfile != null) {
- activeDevice = headsetProfile.getActiveDevice();
+ if (haActiveDevice != null) {
+ return haActiveDevice;
}
- return activeDevice;
+
+ if (leAudioActiveDevice != null) {
+ return leAudioActiveDevice;
+ }
+
+ if (headsetProfile != null && headsetProfile.getActiveDevice() != null) {
+ return headsetProfile.getActiveDevice();
+ }
+
+ return null;
}
}
diff --git a/src/com/android/settings/sound/MediaOutputPreferenceController.java b/src/com/android/settings/sound/MediaOutputPreferenceController.java
index 4ec00e358a950e20b76189570d7933fa057ec09c..758f7e33383335430c944279e719adcb5c7e8bd8 100644
--- a/src/com/android/settings/sound/MediaOutputPreferenceController.java
+++ b/src/com/android/settings/sound/MediaOutputPreferenceController.java
@@ -88,9 +88,11 @@ public class MediaOutputPreferenceController extends AudioSwitchPreferenceContro
// Find active device and set its name as the preference's summary
List connectedA2dpDevices = getConnectedA2dpDevices();
List connectedHADevices = getConnectedHearingAidDevices();
+ List connectedLeAudioDevices = getConnectedLeAudioDevices();
if (mAudioManager.getMode() == AudioManager.MODE_NORMAL
&& ((connectedA2dpDevices != null && !connectedA2dpDevices.isEmpty())
- || (connectedHADevices != null && !connectedHADevices.isEmpty()))) {
+ || (connectedHADevices != null && !connectedHADevices.isEmpty())
+ || (connectedLeAudioDevices != null && !connectedLeAudioDevices.isEmpty()))) {
activeDevice = findActiveDevice();
}
mPreference.setTitle(mContext.getString(R.string.media_output_label_title,
@@ -103,13 +105,23 @@ public class MediaOutputPreferenceController extends AudioSwitchPreferenceContro
@Override
public BluetoothDevice findActiveDevice() {
- BluetoothDevice activeDevice = findActiveHearingAidDevice();
+ BluetoothDevice haActiveDevice = findActiveHearingAidDevice();
+ BluetoothDevice leAudioActiveDevice = findActiveLeAudioDevice();
final A2dpProfile a2dpProfile = mProfileManager.getA2dpProfile();
- if (activeDevice == null && a2dpProfile != null) {
- activeDevice = a2dpProfile.getActiveDevice();
+ if (haActiveDevice != null) {
+ return haActiveDevice;
}
- return activeDevice;
+
+ if (leAudioActiveDevice != null) {
+ return leAudioActiveDevice;
+ }
+
+ if (a2dpProfile != null && a2dpProfile.getActiveDevice() != null) {
+ return a2dpProfile.getActiveDevice();
+ }
+
+ return null;
}
/**
diff --git a/src/com/android/settings/survey/SurveyMixin.java b/src/com/android/settings/survey/SurveyMixin.java
index 5de265347e690bc7ee96cf34edfe8fcd85dbc53a..2f68de621947b282c511ac82f91665a19d3613f3 100644
--- a/src/com/android/settings/survey/SurveyMixin.java
+++ b/src/com/android/settings/survey/SurveyMixin.java
@@ -16,14 +16,12 @@
package com.android.settings.survey;
import android.app.Activity;
-import android.content.BroadcastReceiver;
import androidx.fragment.app.Fragment;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.overlay.SurveyFeatureProvider;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
-import com.android.settingslib.core.lifecycle.events.OnPause;
import com.android.settingslib.core.lifecycle.events.OnResume;
/**
@@ -31,17 +29,17 @@ import com.android.settingslib.core.lifecycle.events.OnResume;
* in settings. This allows new classes to automatically support settings provided the extend
* one of the relevant classes in com.android.settings.lifecycle.
*/
-public class SurveyMixin implements LifecycleObserver, OnResume, OnPause {
+public class SurveyMixin implements LifecycleObserver, OnResume {
private String mName;
private Fragment mFragment;
- private BroadcastReceiver mReceiver;
/**
* A mixin that attempts to perform survey related tasks right before onResume is called
* in a Settings PreferenceFragment. This will allow for remote updating and creation of
* surveys.
- * @param fragment The fragment that this mixin will be attached to.
+ *
+ * @param fragment The fragment that this mixin will be attached to.
* @param fragmentName The simple name of the fragment.
*/
public SurveyMixin(Fragment fragment, String fragmentName) {
@@ -53,31 +51,13 @@ public class SurveyMixin implements LifecycleObserver, OnResume, OnPause {
public void onResume() {
Activity activity = mFragment.getActivity();
- // guard against the activity not existing yet or the feature being disabled
+ // guard against the activity not existing yet
if (activity != null) {
SurveyFeatureProvider provider =
FeatureFactory.getFactory(activity).getSurveyFeatureProvider(activity);
if (provider != null) {
-
- // Try to download a survey if there is none available, show the survey otherwise
- String id = provider.getSurveyId(activity, mName);
- if (provider.getSurveyExpirationDate(activity, id) <= -1) {
- // register the receiver to show the survey on completion.
- mReceiver = provider.createAndRegisterReceiver(activity);
- provider.downloadSurvey(activity, id, null /* data */);
- } else {
- provider.showSurveyIfAvailable(activity, id);
- }
+ provider.sendActivityIfAvailable(mName);
}
}
}
-
- @Override
- public void onPause() {
- Activity activity = mFragment.getActivity();
- if (mReceiver != null && activity != null) {
- SurveyFeatureProvider.unregisterReceiver(activity, mReceiver);
- mReceiver = null;
- }
- }
}
diff --git a/src/com/android/settings/users/AddSupervisedUserActivity.java b/src/com/android/settings/users/AddSupervisedUserActivity.java
deleted file mode 100644
index 8a3221d2816a89cac1bc3dbe01f0a73e159a7433..0000000000000000000000000000000000000000
--- a/src/com/android/settings/users/AddSupervisedUserActivity.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright (C) 2021 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.users;
-
-import android.app.Activity;
-import android.app.ActivityManager;
-import android.app.AlertDialog;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.Looper;
-import android.os.NewUserRequest;
-import android.os.NewUserResponse;
-import android.os.UserManager;
-
-import androidx.annotation.Nullable;
-
-import com.android.settings.R;
-
-import java.util.Objects;
-import java.util.concurrent.Executors;
-import java.util.function.Consumer;
-
-/**
- * Fallback activity for supervised user creation.
- * Built to test {@link UserManager#createUser(NewUserRequest)} API.
- */
-// TODO(b/209659998): [to-be-removed] fallback activity for supervised user creation.
-public class AddSupervisedUserActivity extends Activity {
-
- private UserManager mUserManager;
- private ActivityManager mActivityManager;
-
- @Override
- protected void onCreate(@Nullable Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- mUserManager = getSystemService(UserManager.class);
- mActivityManager = getSystemService(ActivityManager.class);
- setContentView(R.layout.add_supervised_user);
- findViewById(R.id.createSupervisedUser).setOnClickListener(v -> createUser());
- }
-
- private void createUserAsync(final NewUserRequest request,
- final Consumer onResponse) {
- Objects.requireNonNull(onResponse);
-
- final Handler mMainThread = new Handler(Looper.getMainLooper());
- Executors.newSingleThreadExecutor().execute(() -> {
- final NewUserResponse response = mUserManager.createUser(request);
- mMainThread.post(() -> onResponse.accept(response));
- });
- }
-
- private void createUser() {
- final NewUserRequest request = new NewUserRequest.Builder()
- .setName(getString(R.string.user_new_user_name))
- .build();
-
- final AlertDialog pleaseWaitDialog = new AlertDialog.Builder(this)
- .setMessage(getString(R.string.creating_new_user_dialog_message))
- .setCancelable(false)
- .create();
-
- pleaseWaitDialog.show();
- createUserAsync(request, response -> {
- pleaseWaitDialog.dismiss();
-
- if (response.isSuccessful()) {
- mActivityManager.switchUser(response.getUser());
- finish();
- } else {
- new AlertDialog.Builder(this)
- .setTitle(getString(R.string.add_user_failed))
- .setMessage(UserManager.UserOperationResult.class.getName()
- + " = " + response.getOperationResult())
- .setNeutralButton(getString(R.string.okay), null)
- .show();
- }
- });
- }
-}
diff --git a/src/com/android/settings/users/TimeoutToUserZeroPreferenceController.java b/src/com/android/settings/users/TimeoutToDockUserPreferenceController.java
similarity index 79%
rename from src/com/android/settings/users/TimeoutToUserZeroPreferenceController.java
rename to src/com/android/settings/users/TimeoutToDockUserPreferenceController.java
index c332726f617786bfb637a718b6c4c12c0eec9cc2..98dca2a9adeb38c12db530d19fed69c223acce0c 100644
--- a/src/com/android/settings/users/TimeoutToUserZeroPreferenceController.java
+++ b/src/com/android/settings/users/TimeoutToDockUserPreferenceController.java
@@ -16,7 +16,7 @@
package com.android.settings.users;
-import static android.provider.Settings.Secure.TIMEOUT_TO_USER_ZERO;
+import static android.provider.Settings.Secure.TIMEOUT_TO_DOCK_USER;
import android.content.Context;
import android.os.UserHandle;
@@ -30,20 +30,20 @@ import java.util.Arrays;
/**
* Controls the preference which launches a settings screen for user to configure whether to
- * automatically switch to the admin user when the device is docked.
+ * automatically switch to the designated Dock User when the device is docked.
*/
-public class TimeoutToUserZeroPreferenceController extends BasePreferenceController {
+public class TimeoutToDockUserPreferenceController extends BasePreferenceController {
private final String[] mEntries;
private final String[] mValues;
- public TimeoutToUserZeroPreferenceController(Context context,
+ public TimeoutToDockUserPreferenceController(Context context,
String preferenceKey) {
super(context, preferenceKey);
mEntries = mContext.getResources().getStringArray(
- com.android.settings.R.array.switch_to_user_zero_when_docked_timeout_entries);
+ com.android.settings.R.array.switch_to_dock_user_when_docked_timeout_entries);
mValues = mContext.getResources().getStringArray(
- com.android.settings.R.array.switch_to_user_zero_when_docked_timeout_values);
+ com.android.settings.R.array.switch_to_dock_user_when_docked_timeout_values);
}
@Override
@@ -57,7 +57,7 @@ public class TimeoutToUserZeroPreferenceController extends BasePreferenceControl
public int getAvailabilityStatus() {
// Feature not available on device.
if (!mContext.getResources().getBoolean(
- com.android.internal.R.bool.config_enableTimeoutToUserZeroWhenDocked)) {
+ com.android.internal.R.bool.config_enableTimeoutToDockUserWhenDocked)) {
return UNSUPPORTED_ON_DEVICE;
}
@@ -68,6 +68,7 @@ public class TimeoutToUserZeroPreferenceController extends BasePreferenceControl
}
// Is currently user zero. Only non user zero can have this setting.
+ // TODO(b/257333623): Allow the Dock User to be non-SystemUser user in HSUM.
if (UserHandle.myUserId() == UserHandle.USER_SYSTEM) {
return DISABLED_FOR_USER;
}
@@ -78,9 +79,9 @@ public class TimeoutToUserZeroPreferenceController extends BasePreferenceControl
@Override
public CharSequence getSummary() {
final String key = Settings.Secure.getStringForUser(mContext.getContentResolver(),
- TIMEOUT_TO_USER_ZERO, UserHandle.myUserId());
+ TIMEOUT_TO_DOCK_USER, UserHandle.myUserId());
final int index = Arrays.asList(mValues).indexOf(key != null ? key :
- mValues[TimeoutToUserZeroSettings.DEFAULT_TIMEOUT_SETTING_VALUE_INDEX]);
+ mValues[TimeoutToDockUserSettings.DEFAULT_TIMEOUT_SETTING_VALUE_INDEX]);
return mEntries[index];
}
diff --git a/src/com/android/settings/users/TimeoutToUserZeroSettings.java b/src/com/android/settings/users/TimeoutToDockUserSettings.java
similarity index 84%
rename from src/com/android/settings/users/TimeoutToUserZeroSettings.java
rename to src/com/android/settings/users/TimeoutToDockUserSettings.java
index 7621ce54969c51b450c7cfcaa8c385719e559ee4..60bbdbbce1d0a0c9aa2d869d3623438ac4037d84 100644
--- a/src/com/android/settings/users/TimeoutToUserZeroSettings.java
+++ b/src/com/android/settings/users/TimeoutToDockUserSettings.java
@@ -16,7 +16,7 @@
package com.android.settings.users;
-import static android.provider.Settings.Secure.TIMEOUT_TO_USER_ZERO;
+import static android.provider.Settings.Secure.TIMEOUT_TO_DOCK_USER;
import android.app.settings.SettingsEnums;
import android.content.Context;
@@ -33,11 +33,12 @@ import java.util.List;
/**
* Setting screen that lists options for users to configure whether to automatically switch to the
- * admin user when the device is docked, and if so duration of the timeout.
+ * Dock User when the device is docked, and if so duration of the timeout.
*/
-public class TimeoutToUserZeroSettings extends RadioButtonPickerFragment {
+public class TimeoutToDockUserSettings extends RadioButtonPickerFragment {
// Index of the default key of the timeout setting if it hasn't been changed by the user.
- public static final int DEFAULT_TIMEOUT_SETTING_VALUE_INDEX = 0;
+ // Default to the smallest non-zero option (which is currently 1 minute).
+ public static final int DEFAULT_TIMEOUT_SETTING_VALUE_INDEX = 1;
// Labels of the options, for example, "never", "after 5 minutes".
private String[] mEntries;
@@ -52,7 +53,7 @@ public class TimeoutToUserZeroSettings extends RadioButtonPickerFragment {
@Override
protected int getPreferenceScreenResId() {
- return R.xml.user_timeout_to_user_zero_settings;
+ return R.xml.user_timeout_to_dock_user_settings;
}
@Override
@@ -60,9 +61,9 @@ public class TimeoutToUserZeroSettings extends RadioButtonPickerFragment {
super.onAttach(context);
mEntries = getContext().getResources().getStringArray(
- R.array.switch_to_user_zero_when_docked_timeout_entries);
+ R.array.switch_to_dock_user_when_docked_timeout_entries);
mValues = getContext().getResources().getStringArray(
- R.array.switch_to_user_zero_when_docked_timeout_values);
+ R.array.switch_to_dock_user_when_docked_timeout_values);
}
@Override
@@ -83,13 +84,13 @@ public class TimeoutToUserZeroSettings extends RadioButtonPickerFragment {
@Override
protected String getDefaultKey() {
final String defaultKey = Settings.Secure.getStringForUser(
- getContext().getContentResolver(), TIMEOUT_TO_USER_ZERO, UserHandle.myUserId());
+ getContext().getContentResolver(), TIMEOUT_TO_DOCK_USER, UserHandle.myUserId());
return defaultKey != null ? defaultKey : mValues[DEFAULT_TIMEOUT_SETTING_VALUE_INDEX];
}
@Override
protected boolean setDefaultKey(String key) {
- Settings.Secure.putStringForUser(getContext().getContentResolver(), TIMEOUT_TO_USER_ZERO,
+ Settings.Secure.putStringForUser(getContext().getContentResolver(), TIMEOUT_TO_DOCK_USER,
key, UserHandle.myUserId());
return true;
}
diff --git a/src/com/android/settings/users/UserSettings.java b/src/com/android/settings/users/UserSettings.java
index de29aa43458d1c042c927932148cfbc6fee3ffc4..f1ee56ccef877fa999108f2467cf8d6484d392bd 100644
--- a/src/com/android/settings/users/UserSettings.java
+++ b/src/com/android/settings/users/UserSettings.java
@@ -125,7 +125,7 @@ public class UserSettings extends SettingsPreferenceFragment
private static final String KEY_ADD_SUPERVISED_USER = "supervised_user_add";
private static final String KEY_ADD_USER_WHEN_LOCKED = "user_settings_add_users_when_locked";
private static final String KEY_MULTIUSER_TOP_INTRO = "multiuser_top_intro";
- private static final String KEY_TIMEOUT_TO_USER_ZERO = "timeout_to_user_zero_preference";
+ private static final String KEY_TIMEOUT_TO_DOCK_USER = "timeout_to_dock_user_preference";
private static final String KEY_GUEST_CATEGORY = "guest_category";
private static final String KEY_GUEST_RESET = "guest_reset";
private static final String KEY_GUEST_EXIT = "guest_exit";
@@ -213,7 +213,7 @@ public class UserSettings extends SettingsPreferenceFragment
private AddUserWhenLockedPreferenceController mAddUserWhenLockedPreferenceController;
private RemoveGuestOnExitPreferenceController mRemoveGuestOnExitPreferenceController;
private MultiUserTopIntroPreferenceController mMultiUserTopIntroPreferenceController;
- private TimeoutToUserZeroPreferenceController mTimeoutToUserZeroPreferenceController;
+ private TimeoutToDockUserPreferenceController mTimeoutToDockUserPreferenceController;
private UserCreatingDialog mUserCreatingDialog;
private final AtomicBoolean mGuestCreationScheduled = new AtomicBoolean();
private final ExecutorService mExecutor = Executors.newSingleThreadExecutor();
@@ -306,14 +306,14 @@ public class UserSettings extends SettingsPreferenceFragment
mMultiUserTopIntroPreferenceController = new MultiUserTopIntroPreferenceController(activity,
KEY_MULTIUSER_TOP_INTRO);
- mTimeoutToUserZeroPreferenceController = new TimeoutToUserZeroPreferenceController(activity,
- KEY_TIMEOUT_TO_USER_ZERO);
+ mTimeoutToDockUserPreferenceController = new TimeoutToDockUserPreferenceController(
+ activity, KEY_TIMEOUT_TO_DOCK_USER);
final PreferenceScreen screen = getPreferenceScreen();
mAddUserWhenLockedPreferenceController.displayPreference(screen);
mRemoveGuestOnExitPreferenceController.displayPreference(screen);
mMultiUserTopIntroPreferenceController.displayPreference(screen);
- mTimeoutToUserZeroPreferenceController.displayPreference(screen);
+ mTimeoutToDockUserPreferenceController.displayPreference(screen);
screen.findPreference(mAddUserWhenLockedPreferenceController.getPreferenceKey())
.setOnPreferenceChangeListener(mAddUserWhenLockedPreferenceController);
@@ -387,8 +387,8 @@ public class UserSettings extends SettingsPreferenceFragment
mAddUserWhenLockedPreferenceController.updateState(screen.findPreference(
mAddUserWhenLockedPreferenceController.getPreferenceKey()));
- mTimeoutToUserZeroPreferenceController.updateState(screen.findPreference(
- mTimeoutToUserZeroPreferenceController.getPreferenceKey()));
+ mTimeoutToDockUserPreferenceController.updateState(screen.findPreference(
+ mTimeoutToDockUserPreferenceController.getPreferenceKey()));
mRemoveGuestOnExitPreferenceController.updateState(screen.findPreference(
mRemoveGuestOnExitPreferenceController.getPreferenceKey()));
if (mShouldUpdateUserList) {
@@ -569,13 +569,6 @@ public class UserSettings extends SettingsPreferenceFragment
.setPackage(mConfigSupervisedUserCreationPackage)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- // TODO(b/209659998): [to-be-removed] fallback activity for supervised user creation.
- if (getActivity().getPackageManager().resolveActivity(intent, 0) == null) {
- intent
- .setClass(getContext(), AddSupervisedUserActivity.class)
- .setPackage(null);
- }
-
startActivity(intent);
}
@@ -1681,7 +1674,10 @@ public class UserSettings extends SettingsPreferenceFragment
}
UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
- Bitmap icon = BitmapFactory.decodeStream(avatarDataStream);
+ Bitmap decodedIcon = BitmapFactory.decodeStream(avatarDataStream);
+ CircleFramedDrawable drawable = CircleFramedDrawable.getInstance(context, decodedIcon);
+ Bitmap icon = UserIcons.convertToBitmapAtUserIconSize(context.getResources(), drawable);
+
um.setUserIcon(userId, icon);
try {
avatarDataStream.close();
diff --git a/src/com/android/settings/vpn2/AdvancedVpnFeatureProvider.java b/src/com/android/settings/vpn2/AdvancedVpnFeatureProvider.java
deleted file mode 100644
index 962b6c2e53b1970e415b6767ef2a2ca9ca290738..0000000000000000000000000000000000000000
--- a/src/com/android/settings/vpn2/AdvancedVpnFeatureProvider.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2022 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.vpn2;
-
-import android.content.Context;
-
-/**
- * Feature Provider used in vpn usage
- */
-public interface AdvancedVpnFeatureProvider {
-
- /**
- * Returns package name of advanced vpn.
- */
- String getAdvancedVpnPackageName();
-
- /**
- * Returns {@code true} advanced vpn is supported.
- */
- boolean isAdvancedVpnSupported(Context context);
-
- /**
- * Returns the title of advanced vpn preference group.
- */
- String getAdvancedVpnPreferenceGroupTitle(Context context);
-
- /**
- * Returns the title of vpn preference group.
- */
- String getVpnPreferenceGroupTitle(Context context);
-
- /**
- * Returns {@code true} advanced vpn is removable.
- */
- boolean isAdvancedVpnRemovable();
-
- /**
- * Returns {@code true} if the disconnect dialog is enabled when advanced vpn is connected.
- */
- boolean isDisconnectDialogEnabled();
-}
diff --git a/src/com/android/settings/vpn2/AdvancedVpnFeatureProviderImpl.java b/src/com/android/settings/vpn2/AdvancedVpnFeatureProviderImpl.java
deleted file mode 100644
index b8f58a9fde754338259a9c25803998e79173bcdb..0000000000000000000000000000000000000000
--- a/src/com/android/settings/vpn2/AdvancedVpnFeatureProviderImpl.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) 2022 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.vpn2;
-
-import android.content.Context;
-
-/**
- * Feature provider implementation for advanced vpn.
- */
-public class AdvancedVpnFeatureProviderImpl implements AdvancedVpnFeatureProvider {
- @Override
- public String getAdvancedVpnPackageName() {
- return null;
- }
-
- @Override
- public boolean isAdvancedVpnSupported(Context context) {
- return false;
- }
-
- @Override
- public String getAdvancedVpnPreferenceGroupTitle(Context context) {
- return null;
- }
-
- @Override
- public String getVpnPreferenceGroupTitle(Context context) {
- return null;
- }
-
- @Override
- public boolean isAdvancedVpnRemovable() {
- return true;
- }
-
- @Override
- public boolean isDisconnectDialogEnabled() {
- return true;
- }
-}
diff --git a/src/com/android/settings/vpn2/AppManagementFragment.java b/src/com/android/settings/vpn2/AppManagementFragment.java
index d2fa5fccbfc6ca36df9f17b045dae99ca21ea7f3..d4ee5b9c476de9c2dfda545658073d5a9d6581e1 100644
--- a/src/com/android/settings/vpn2/AppManagementFragment.java
+++ b/src/com/android/settings/vpn2/AppManagementFragment.java
@@ -48,7 +48,6 @@ import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
-import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import com.android.settingslib.RestrictedPreference;
@@ -72,7 +71,6 @@ public class AppManagementFragment extends SettingsPreferenceFragment
private PackageManager mPackageManager;
private DevicePolicyManager mDevicePolicyManager;
private VpnManager mVpnManager;
- private AdvancedVpnFeatureProvider mFeatureProvider;
// VPN app info
private final int mUserId = UserHandle.myUserId();
@@ -124,7 +122,6 @@ public class AppManagementFragment extends SettingsPreferenceFragment
mPackageManager = getContext().getPackageManager();
mDevicePolicyManager = getContext().getSystemService(DevicePolicyManager.class);
mVpnManager = getContext().getSystemService(VpnManager.class);
- mFeatureProvider = FeatureFactory.getFactory(getContext()).getAdvancedVpnFeatureProvider();
mPreferenceAlwaysOn = (RestrictedSwitchPreference) findPreference(KEY_ALWAYS_ON_VPN);
mPreferenceLockdown = (RestrictedSwitchPreference) findPreference(KEY_LOCKDOWN_VPN);
@@ -286,16 +283,7 @@ public class AppManagementFragment extends SettingsPreferenceFragment
}
}
- @VisibleForTesting
- void updateRestrictedViews() {
- if (mFeatureProvider.isAdvancedVpnSupported(getContext())
- && !mFeatureProvider.isAdvancedVpnRemovable()
- && TextUtils.equals(mPackageName, mFeatureProvider.getAdvancedVpnPackageName())) {
- mPreferenceForget.setVisible(false);
- } else {
- mPreferenceForget.setVisible(true);
- }
-
+ private void updateRestrictedViews() {
if (isAdded()) {
mPreferenceAlwaysOn.checkRestrictionAndSetDisabled(UserManager.DISALLOW_CONFIG_VPN,
mUserId);
@@ -326,14 +314,6 @@ public class AppManagementFragment extends SettingsPreferenceFragment
}
}
- @VisibleForTesting
- void init(String packageName, AdvancedVpnFeatureProvider featureProvider,
- RestrictedPreference preference) {
- mPackageName = packageName;
- mFeatureProvider = featureProvider;
- mPreferenceForget = preference;
- }
-
private String getAlwaysOnVpnPackage() {
return mVpnManager.getAlwaysOnVpnPackageForUser(mUserId);
}
diff --git a/src/com/android/settings/vpn2/VpnSettings.java b/src/com/android/settings/vpn2/VpnSettings.java
index a91bb6c7e66d67a9d810d0044ea05ea54eb5ff70..e89785fe535e04abbd7f30000863f0016f74713e 100644
--- a/src/com/android/settings/vpn2/VpnSettings.java
+++ b/src/com/android/settings/vpn2/VpnSettings.java
@@ -26,7 +26,6 @@ import android.app.AppOpsManager;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.Intent;
-import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
@@ -43,7 +42,6 @@ import android.os.UserHandle;
import android.os.UserManager;
import android.security.Credentials;
import android.security.LegacyVpnProfileStore;
-import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.Log;
@@ -54,7 +52,6 @@ import android.view.MenuItem;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.PreferenceGroup;
-import androidx.preference.PreferenceScreen;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.net.LegacyVpnInfo;
@@ -62,7 +59,6 @@ import com.android.internal.net.VpnConfig;
import com.android.internal.net.VpnProfile;
import com.android.settings.R;
import com.android.settings.RestrictedSettingsFragment;
-import com.android.settings.overlay.FeatureFactory;
import com.android.settings.widget.GearPreference;
import com.android.settings.widget.GearPreference.OnGearClickListener;
import com.android.settingslib.RestrictedLockUtilsInternal;
@@ -83,12 +79,9 @@ import java.util.Set;
public class VpnSettings extends RestrictedSettingsFragment implements
Handler.Callback, Preference.OnPreferenceClickListener {
private static final String LOG_TAG = "VpnSettings";
- private static final boolean DEBUG = Log.isLoggable(LOG_TAG, Log.DEBUG);
private static final int RESCAN_MESSAGE = 0;
private static final int RESCAN_INTERVAL_MS = 1000;
- private static final String ADVANCED_VPN_GROUP_KEY = "advanced_vpn_group";
- private static final String VPN_GROUP_KEY = "vpn_group";
private static final NetworkRequest VPN_REQUEST = new NetworkRequest.Builder()
.removeCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN)
@@ -109,9 +102,6 @@ public class VpnSettings extends RestrictedSettingsFragment implements
private LegacyVpnInfo mConnectedLegacyVpn;
private boolean mUnavailable;
- private AdvancedVpnFeatureProvider mFeatureProvider;
- private PreferenceScreen mPreferenceScreen;
- private boolean mIsAdvancedVpnSupported;
public VpnSettings() {
super(UserManager.DISALLOW_CONFIG_VPN);
@@ -129,14 +119,11 @@ public class VpnSettings extends RestrictedSettingsFragment implements
mUserManager = (UserManager) getSystemService(Context.USER_SERVICE);
mConnectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
mVpnManager = (VpnManager) getSystemService(Context.VPN_MANAGEMENT_SERVICE);
- mFeatureProvider = FeatureFactory.getFactory(getContext()).getAdvancedVpnFeatureProvider();
- mIsAdvancedVpnSupported = mFeatureProvider.isAdvancedVpnSupported(getContext());
mUnavailable = isUiRestricted();
setHasOptionsMenu(!mUnavailable);
addPreferencesFromResource(R.xml.vpn_settings2);
- mPreferenceScreen = getPreferenceScreen();
}
@Override
@@ -242,8 +229,7 @@ public class VpnSettings extends RestrictedSettingsFragment implements
// Run heavy RPCs before switching to UI thread
final List vpnProfiles = loadVpnProfiles();
- final List vpnApps = getVpnApps(context, /* includeProfiles */ true,
- mFeatureProvider);
+ final List vpnApps = getVpnApps(context, /* includeProfiles */ true);
final Map connectedLegacyVpns = getConnectedLegacyVpns();
final Set connectedAppVpns = getConnectedAppVpns();
@@ -279,7 +265,7 @@ public class VpnSettings extends RestrictedSettingsFragment implements
private final VpnSettings mSettings;
- UpdatePreferences(VpnSettings settings) {
+ public UpdatePreferences(VpnSettings settings) {
mSettings = settings;
}
@@ -346,14 +332,7 @@ public class VpnSettings extends RestrictedSettingsFragment implements
}
// Trim out deleted VPN preferences
- if (DEBUG) {
- Log.d(LOG_TAG, "isAdvancedVpnSupported() : " + mSettings.mIsAdvancedVpnSupported);
- }
- if (mSettings.mIsAdvancedVpnSupported) {
- mSettings.setShownAdvancedPreferences(updates);
- } else {
- mSettings.setShownPreferences(updates);
- }
+ mSettings.setShownPreferences(updates);
}
}
@@ -364,61 +343,12 @@ public class VpnSettings extends RestrictedSettingsFragment implements
@VisibleForTesting @UiThread
public void setShownPreferences(final Collection updates) {
- retainAllPreference(updates);
-
- final PreferenceGroup vpnGroup = mPreferenceScreen;
- updatePreferenceGroup(vpnGroup, updates);
-
- // Show all new preferences on the screen
- for (Preference pref : updates) {
- vpnGroup.addPreference(pref);
- }
- }
-
- @VisibleForTesting @UiThread
- void setShownAdvancedPreferences(final Collection updates) {
- retainAllPreference(updates);
-
- PreferenceGroup advancedVpnGroup = mPreferenceScreen.findPreference(ADVANCED_VPN_GROUP_KEY);
- PreferenceGroup vpnGroup = mPreferenceScreen.findPreference(VPN_GROUP_KEY);
- advancedVpnGroup.setTitle(
- mFeatureProvider.getAdvancedVpnPreferenceGroupTitle(getContext()));
- vpnGroup.setTitle(mFeatureProvider.getVpnPreferenceGroupTitle(getContext()));
- updatePreferenceGroup(advancedVpnGroup, updates);
- updatePreferenceGroup(vpnGroup, updates);
-
- // Show all new preferences on the screen
- for (Preference pref : updates) {
- String packageName = "";
- if (pref instanceof LegacyVpnPreference) {
- LegacyVpnPreference legacyPref = (LegacyVpnPreference) pref;
- packageName = legacyPref.getPackageName();
- } else if (pref instanceof AppPreference) {
- AppPreference appPref = (AppPreference) pref;
- packageName = appPref.getPackageName();
- }
- if (DEBUG) {
- Log.d(LOG_TAG, "setShownAdvancedPreferences() package name : " + packageName);
- }
- if (TextUtils.equals(packageName, mFeatureProvider.getAdvancedVpnPackageName())) {
- advancedVpnGroup.addPreference(pref);
- } else {
- vpnGroup.addPreference(pref);
- }
- }
-
- advancedVpnGroup.setVisible(advancedVpnGroup.getPreferenceCount() > 0);
- vpnGroup.setVisible(vpnGroup.getPreferenceCount() > 0);
- }
-
- private void retainAllPreference(Collection updates) {
mLegacyVpnPreferences.values().retainAll(updates);
mAppPreferences.values().retainAll(updates);
- }
- private void updatePreferenceGroup(PreferenceGroup vpnGroup, Collection updates) {
// Change {@param updates} in-place to only contain new preferences that were not already
// added to the preference screen.
+ final PreferenceGroup vpnGroup = getPreferenceScreen();
for (int i = vpnGroup.getPreferenceCount() - 1; i >= 0; i--) {
Preference p = vpnGroup.getPreference(i);
if (updates.contains(p)) {
@@ -427,6 +357,11 @@ public class VpnSettings extends RestrictedSettingsFragment implements
vpnGroup.removePreference(p);
}
}
+
+ // Show any new preferences on the screen
+ for (Preference pref : updates) {
+ vpnGroup.addPreference(pref);
+ }
}
@Override
@@ -448,16 +383,14 @@ public class VpnSettings extends RestrictedSettingsFragment implements
} else if (preference instanceof AppPreference) {
AppPreference pref = (AppPreference) preference;
boolean connected = (pref.getState() == AppPreference.STATE_CONNECTED);
- String vpnPackageName = pref.getPackageName();
- if ((!connected) || (isAdvancedVpn(mFeatureProvider, vpnPackageName, getContext())
- && !mFeatureProvider.isDisconnectDialogEnabled())) {
+ if (!connected) {
try {
UserHandle user = UserHandle.of(pref.getUserId());
- Context userContext = getContext().createPackageContextAsUser(
- getContext().getPackageName(), 0 /* flags */, user);
+ Context userContext = getActivity().createPackageContextAsUser(
+ getActivity().getPackageName(), 0 /* flags */, user);
PackageManager pm = userContext.getPackageManager();
- Intent appIntent = pm.getLaunchIntentForPackage(vpnPackageName);
+ Intent appIntent = pm.getLaunchIntentForPackage(pref.getPackageName());
if (appIntent != null) {
userContext.startActivityAsUser(appIntent, user);
return true;
@@ -537,32 +470,9 @@ public class VpnSettings extends RestrictedSettingsFragment implements
pref.setOnPreferenceClickListener(this);
mAppPreferences.put(app, pref);
}
- enableAdvancedVpnGearIconIfNecessary(pref);
return pref;
}
- private void enableAdvancedVpnGearIconIfNecessary(AppPreference pref) {
- Context context = getContext();
- if (!isAdvancedVpn(mFeatureProvider, pref.getPackageName(), context)) {
- return;
- }
-
- boolean isEnabled = false;
- AppOpsManager appOpsManager = getContext().getSystemService(AppOpsManager.class);
- List apps =
- appOpsManager.getPackagesForOps(
- new int[] {OP_ACTIVATE_VPN, OP_ACTIVATE_PLATFORM_VPN});
- if (apps != null) {
- for (AppOpsManager.PackageOps pkg : apps) {
- if (isAdvancedVpn(mFeatureProvider, pkg.getPackageName(), context)) {
- isEnabled = true;
- break;
- }
- }
- }
- pref.setOnGearClickListener(isEnabled ? mGearListener : null);
- }
-
@WorkerThread
private Map getConnectedLegacyVpns() {
mConnectedLegacyVpn = mVpnManager.getLegacyVpnInfo(UserHandle.myUserId());
@@ -598,15 +508,7 @@ public class VpnSettings extends RestrictedSettingsFragment implements
return result;
}
- static List getVpnApps(Context context, boolean includeProfiles,
- AdvancedVpnFeatureProvider featureProvider) {
- return getVpnApps(context, includeProfiles, featureProvider,
- context.getSystemService(AppOpsManager.class));
- }
-
- @VisibleForTesting
- static List getVpnApps(Context context, boolean includeProfiles,
- AdvancedVpnFeatureProvider featureProvider, AppOpsManager aom) {
+ static List getVpnApps(Context context, boolean includeProfiles) {
List result = Lists.newArrayList();
final Set profileIds;
@@ -619,19 +521,8 @@ public class VpnSettings extends RestrictedSettingsFragment implements
profileIds = Collections.singleton(UserHandle.myUserId());
}
- if (featureProvider.isAdvancedVpnSupported(context)) {
- PackageManager pm = context.getPackageManager();
- try {
- ApplicationInfo appInfo =
- pm.getApplicationInfo(
- featureProvider.getAdvancedVpnPackageName(), /* flags= */ 0);
- int userId = UserHandle.getUserId(appInfo.uid);
- result.add(new AppVpnInfo(userId, featureProvider.getAdvancedVpnPackageName()));
- } catch (PackageManager.NameNotFoundException e) {
- Log.e(LOG_TAG, "Advanced VPN package name not found.", e);
- }
- }
-
+ // Fetch VPN-enabled apps from AppOps.
+ AppOpsManager aom = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
List apps =
aom.getPackagesForOps(new int[] {OP_ACTIVATE_VPN, OP_ACTIVATE_PLATFORM_VPN});
if (apps != null) {
@@ -641,9 +532,6 @@ public class VpnSettings extends RestrictedSettingsFragment implements
// Skip packages for users outside of our profile group.
continue;
}
- if (isAdvancedVpn(featureProvider, pkg.getPackageName(), context)) {
- continue;
- }
// Look for a MODE_ALLOWED permission to activate VPN.
boolean allowed = false;
for (AppOpsManager.OpEntry op : pkg.getOps()) {
@@ -662,12 +550,6 @@ public class VpnSettings extends RestrictedSettingsFragment implements
return result;
}
- private static boolean isAdvancedVpn(AdvancedVpnFeatureProvider featureProvider,
- String packageName, Context context) {
- return featureProvider.isAdvancedVpnSupported(context)
- && TextUtils.equals(packageName, featureProvider.getAdvancedVpnPackageName());
- }
-
private static List loadVpnProfiles() {
final ArrayList result = Lists.newArrayList();
@@ -680,10 +562,4 @@ public class VpnSettings extends RestrictedSettingsFragment implements
}
return result;
}
-
- @VisibleForTesting
- void init(PreferenceScreen preferenceScreen, AdvancedVpnFeatureProvider featureProvider) {
- mPreferenceScreen = preferenceScreen;
- mFeatureProvider = featureProvider;
- }
}
diff --git a/src/com/android/settings/wifi/NetworkRequestDialogFragment.java b/src/com/android/settings/wifi/NetworkRequestDialogFragment.java
index 5fe156c3dbfbaa59f333958e97a7a5c579b9f9eb..56390471df5edd309f08100727193b015c71b0f8 100644
--- a/src/com/android/settings/wifi/NetworkRequestDialogFragment.java
+++ b/src/com/android/settings/wifi/NetworkRequestDialogFragment.java
@@ -16,7 +16,7 @@
package com.android.settings.wifi;
-import static com.android.settings.wifi.WifiUtils.getWifiEntrySecurity;
+import static com.android.wifitrackerlib.Utils.getSecurityTypesFromScanResult;
import static java.util.stream.Collectors.toList;
@@ -77,8 +77,12 @@ public class NetworkRequestDialogFragment extends NetworkRequestDialogBaseFragme
private static final int MAX_NUMBER_LIST_ITEM = 5;
private boolean mShowLimitedItem = true;
+ private static class MatchWifi {
+ String mSsid;
+ List mSecurityTypes;
+ }
+ private List mMatchWifis = new ArrayList<>();
@VisibleForTesting List mFilteredWifiEntries = new ArrayList<>();
- @VisibleForTesting List mMatchedScanResults = new ArrayList<>();
private WifiEntryAdapter mDialogAdapter;
private NetworkRequestUserSelectionCallback mUserSelectionCallback;
@@ -237,7 +241,7 @@ public class NetworkRequestDialogFragment extends NetworkRequestDialogBaseFragme
/** Called when the state of Wifi has changed. */
@Override
public void onWifiStateChanged() {
- if (mMatchedScanResults.size() == 0) {
+ if (mMatchWifis.size() == 0) {
return;
}
updateWifiEntries();
@@ -249,7 +253,7 @@ public class NetworkRequestDialogFragment extends NetworkRequestDialogBaseFragme
*/
@Override
public void onWifiEntriesChanged() {
- if (mMatchedScanResults.size() == 0) {
+ if (mMatchWifis.size() == 0) {
return;
}
updateWifiEntries();
@@ -275,16 +279,24 @@ public class NetworkRequestDialogFragment extends NetworkRequestDialogBaseFragme
wifiEntries.addAll(mWifiPickerTracker.getWifiEntries());
mFilteredWifiEntries.clear();
- mFilteredWifiEntries.addAll(wifiEntries.stream().filter(entry -> {
- for (ScanResult matchedScanResult : mMatchedScanResults) {
- if (TextUtils.equals(entry.getSsid(), matchedScanResult.SSID)
- && entry.getSecurity() == getWifiEntrySecurity(matchedScanResult)) {
+ mFilteredWifiEntries.addAll(wifiEntries.stream()
+ .filter(entry -> isMatchedWifiEntry(entry))
+ .limit(mShowLimitedItem ? MAX_NUMBER_LIST_ITEM : Long.MAX_VALUE)
+ .collect(toList()));
+ }
+
+ private boolean isMatchedWifiEntry(WifiEntry entry) {
+ for (MatchWifi wifi : mMatchWifis) {
+ if (!TextUtils.equals(entry.getSsid(), wifi.mSsid)) {
+ continue;
+ }
+ for (Integer security : wifi.mSecurityTypes) {
+ if (entry.getSecurityTypes().contains(security)) {
return true;
}
}
- return false;
- }).limit(mShowLimitedItem ? MAX_NUMBER_LIST_ITEM : Long.MAX_VALUE)
- .collect(toList()));
+ }
+ return false;
}
private class WifiEntryAdapter extends ArrayAdapter {
@@ -350,7 +362,14 @@ public class NetworkRequestDialogFragment extends NetworkRequestDialogBaseFragme
@Override
public void onMatch(List scanResults) {
- mMatchedScanResults = scanResults;
+ mMatchWifis.clear();
+ for (ScanResult scanResult : scanResults) {
+ MatchWifi matchWifi = new MatchWifi();
+ matchWifi.mSsid = scanResult.SSID;
+ matchWifi.mSecurityTypes = getSecurityTypesFromScanResult(scanResult);
+ mMatchWifis.add(matchWifi);
+ }
+
updateWifiEntries();
updateUi();
}
diff --git a/src/com/android/settings/wifi/WifiUtils.java b/src/com/android/settings/wifi/WifiUtils.java
index 4a3616a28e05db3d00036f3873edb1e33f0ea3fc..68d8bebd58269e21c4ff27b1c69e70c4684f6b85 100644
--- a/src/com/android/settings/wifi/WifiUtils.java
+++ b/src/com/android/settings/wifi/WifiUtils.java
@@ -22,14 +22,20 @@ import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.PackageManager;
import android.net.NetworkCapabilities;
+import android.net.TetheringManager;
import android.net.wifi.ScanResult;
import android.net.wifi.SoftApConfiguration;
import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiManager;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
import android.text.TextUtils;
+import android.util.Log;
+import androidx.annotation.VisibleForTesting;
+
+import com.android.settings.R;
import com.android.settings.Utils;
import com.android.wifitrackerlib.WifiEntry;
@@ -38,12 +44,16 @@ import java.nio.charset.StandardCharsets;
/** A utility class for Wi-Fi functions. */
public class WifiUtils extends com.android.settingslib.wifi.WifiUtils {
+ static final String TAG = "WifiUtils";
+
private static final int SSID_ASCII_MIN_LENGTH = 1;
private static final int SSID_ASCII_MAX_LENGTH = 32;
private static final int PSK_PASSPHRASE_ASCII_MIN_LENGTH = 8;
private static final int PSK_PASSPHRASE_ASCII_MAX_LENGTH = 63;
+ private static Boolean sCanShowWifiHotspotCached;
+
public static boolean isSSIDTooLong(String ssid) {
if (TextUtils.isEmpty(ssid)) {
return false;
@@ -240,4 +250,62 @@ public class WifiUtils extends com.android.settingslib.wifi.WifiUtils {
return WifiEntry.SECURITY_NONE;
}
+
+ /**
+ * Check if Wi-Fi hotspot settings can be displayed.
+ *
+ * @param context Context of caller
+ * @return true if Wi-Fi hotspot settings can be displayed
+ */
+ public static boolean checkShowWifiHotspot(Context context) {
+ if (context == null) return false;
+
+ boolean showWifiHotspotSettings =
+ context.getResources().getBoolean(R.bool.config_show_wifi_hotspot_settings);
+ if (!showWifiHotspotSettings) {
+ Log.w(TAG, "config_show_wifi_hotspot_settings:false");
+ return false;
+ }
+
+ WifiManager wifiManager = context.getSystemService(WifiManager.class);
+ if (wifiManager == null) {
+ Log.e(TAG, "WifiManager is null");
+ return false;
+ }
+
+ TetheringManager tetheringManager = context.getSystemService(TetheringManager.class);
+ if (tetheringManager == null) {
+ Log.e(TAG, "TetheringManager is null");
+ return false;
+ }
+ String[] wifiRegexs = tetheringManager.getTetherableWifiRegexs();
+ if (wifiRegexs == null || wifiRegexs.length == 0) {
+ Log.w(TAG, "TetherableWifiRegexs is empty");
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Return the cached result to see if Wi-Fi hotspot settings can be displayed.
+ *
+ * @param context Context of caller
+ * @return true if Wi-Fi hotspot settings can be displayed
+ */
+ public static boolean canShowWifiHotspot(Context context) {
+ if (sCanShowWifiHotspotCached == null) {
+ sCanShowWifiHotspotCached = checkShowWifiHotspot(context);
+ }
+ return sCanShowWifiHotspotCached;
+ }
+
+ /**
+ * Sets the sCanShowWifiHotspotCached for testing purposes.
+ *
+ * @param cached Cached value for #canShowWifiHotspot()
+ */
+ @VisibleForTesting
+ public static void setCanShowWifiHotspotCached(Boolean cached) {
+ sCanShowWifiHotspotCached = cached;
+ }
}
diff --git a/src/com/android/settings/wifi/calling/WifiCallingSliceHelper.java b/src/com/android/settings/wifi/calling/WifiCallingSliceHelper.java
index c73bffa7411b29fbd016c84f274e2c63a63ec38f..522d697299c6c78afaf581d2b7bbb151bc5ffe54 100644
--- a/src/com/android/settings/wifi/calling/WifiCallingSliceHelper.java
+++ b/src/com/android/settings/wifi/calling/WifiCallingSliceHelper.java
@@ -376,15 +376,17 @@ public class WifiCallingSliceHelper {
final WifiCallingQueryImsState queryState = queryImsState(subId);
if (queryState.isWifiCallingProvisioned()) {
final boolean currentValue = isWifiCallingEnabled();
- final boolean newValue = intent.getBooleanExtra(EXTRA_TOGGLE_STATE,
- currentValue);
+ final boolean newValue = !(intent.getBooleanExtra(EXTRA_TOGGLE_STATE,
+ currentValue));
final Intent activationAppIntent =
getWifiCallingCarrierActivityIntent(subId);
- if ((newValue == currentValue) && activationAppIntent == null) {
+ // 1. If activationApp is not null, users only can turn off WFC, or
+ // 2. Turn on/off directly if there is no activationApp.
+ if ((newValue != currentValue) && (activationAppIntent == null || !newValue)) {
// If either the action is to turn off wifi calling setting
// or there is no activation involved - Update the setting
final ImsMmTelManager imsMmTelManager = getImsMmTelManager(subId);
- imsMmTelManager.setVoWiFiSettingEnabled(!newValue);
+ imsMmTelManager.setVoWiFiSettingEnabled(newValue);
} else {
Log.w(TAG, "action not taken: subId " + subId
+ " from " + currentValue + " to " + newValue);
diff --git a/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivity.java b/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivity.java
index e6f0b31f3842a5e4c45f6cf44567a52e1fe258dc..6c9d4980f4495d580c62e4839bd7bfd852c4c724 100644
--- a/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivity.java
+++ b/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivity.java
@@ -28,6 +28,7 @@ import android.os.UserManager;
import android.provider.Settings;
import android.util.EventLog;
import android.util.Log;
+import android.view.WindowManager;
import androidx.annotation.VisibleForTesting;
import androidx.fragment.app.FragmentTransaction;
@@ -99,6 +100,7 @@ public class WifiDppConfiguratorActivity extends WifiDppBaseActivity implements
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
if (savedInstanceState != null) {
String qrCode = savedInstanceState.getString(KEY_QR_CODE);
diff --git a/src/com/android/settings/wifi/tether/WifiTetherPreferenceController.java b/src/com/android/settings/wifi/tether/WifiTetherPreferenceController.java
index 73ff31d4e4753d22af05f2f2076aa0245531d33c..a9c35594e33232f80a911f8830bcadc06950e213 100644
--- a/src/com/android/settings/wifi/tether/WifiTetherPreferenceController.java
+++ b/src/com/android/settings/wifi/tether/WifiTetherPreferenceController.java
@@ -16,9 +16,10 @@
package com.android.settings.wifi.tether;
+import static com.android.settings.wifi.WifiUtils.canShowWifiHotspot;
+
import android.annotation.NonNull;
import android.content.Context;
-import android.net.TetheringManager;
import android.net.wifi.SoftApConfiguration;
import android.net.wifi.WifiClient;
import android.net.wifi.WifiManager;
@@ -46,7 +47,6 @@ public class WifiTetherPreferenceController extends AbstractPreferenceController
private static final String WIFI_TETHER_SETTINGS = "wifi_tether";
- private boolean mIsWifiTetherable;
private WifiManager mWifiManager;
private boolean mIsWifiTetheringAllow;
private int mSoftApState;
@@ -57,8 +57,7 @@ public class WifiTetherPreferenceController extends AbstractPreferenceController
public WifiTetherPreferenceController(Context context, Lifecycle lifecycle) {
this(context, lifecycle,
- context.getSystemService(WifiManager.class),
- context.getSystemService(TetheringManager.class),
+ context.getApplicationContext().getSystemService(WifiManager.class),
true /* initSoftApManager */,
WifiEnterpriseRestrictionUtils.isWifiTetheringAllowed(context));
}
@@ -68,15 +67,9 @@ public class WifiTetherPreferenceController extends AbstractPreferenceController
Context context,
Lifecycle lifecycle,
WifiManager wifiManager,
- TetheringManager tetheringManager,
boolean initSoftApManager,
boolean isWifiTetheringAllow) {
super(context);
- final String[] wifiRegexs = tetheringManager.getTetherableWifiRegexs();
- if (wifiRegexs != null && wifiRegexs.length != 0) {
- mIsWifiTetherable = true;
- }
-
mIsWifiTetheringAllow = isWifiTetheringAllow;
if (!isWifiTetheringAllow) return;
@@ -92,7 +85,7 @@ public class WifiTetherPreferenceController extends AbstractPreferenceController
@Override
public boolean isAvailable() {
- return mIsWifiTetherable && !Utils.isMonkeyRunning();
+ return canShowWifiHotspot(mContext) && !Utils.isMonkeyRunning();
}
@Override
diff --git a/src/com/android/settings/wifi/tether/WifiTetherSettings.java b/src/com/android/settings/wifi/tether/WifiTetherSettings.java
index 5b9ce420e5c42f1ab36275e748f11fff78b69484..47dba765e5fb1b19bc27d30463f894f07516ec9e 100644
--- a/src/com/android/settings/wifi/tether/WifiTetherSettings.java
+++ b/src/com/android/settings/wifi/tether/WifiTetherSettings.java
@@ -18,6 +18,8 @@ package com.android.settings.wifi.tether;
import static android.net.wifi.WifiManager.WIFI_AP_STATE_CHANGED_ACTION;
+import static com.android.settings.wifi.WifiUtils.canShowWifiHotspot;
+
import android.app.settings.SettingsEnums;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -39,6 +41,7 @@ import com.android.settings.core.FeatureFlags;
import com.android.settings.dashboard.RestrictedDashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.widget.SettingsMainSwitchBar;
+import com.android.settings.wifi.WifiUtils;
import com.android.settingslib.TetherUtil;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.search.SearchIndexable;
@@ -108,6 +111,13 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
+ if (!canShowWifiHotspot(getContext())) {
+ Log.e(TAG, "can not launch Wi-Fi hotspot settings"
+ + " because the config is not set to show.");
+ finish();
+ return;
+ }
+
setIfOnlyAvailableForAdmins(true);
mUnavailable = isUiRestricted() || !mWifiRestriction.isHotspotAvailable(getContext());
}
@@ -287,12 +297,12 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
@Override
protected boolean isPageSearchEnabled(Context context) {
+ if (context == null || !WifiUtils.canShowWifiHotspot(context)) return false;
return !FeatureFlagUtils.isEnabled(context, FeatureFlags.TETHER_ALL_IN_ONE);
}
@Override
- public List createPreferenceControllers(
- Context context) {
+ public List createPreferenceControllers(Context context) {
return buildPreferenceControllers(context, null /* listener */);
}
}
diff --git a/tests/robotests/src/com/android/settings/TetherSettingsTest.java b/tests/robotests/src/com/android/settings/TetherSettingsTest.java
index 71cb9d21045fc9142f3081a396319d3da194138f..79814b3b6d2939b67c6f368c83eee7768fe5a47e 100644
--- a/tests/robotests/src/com/android/settings/TetherSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/TetherSettingsTest.java
@@ -20,6 +20,8 @@ import static android.content.Intent.ACTION_MEDIA_SHARED;
import static android.content.Intent.ACTION_MEDIA_UNSHARED;
import static android.hardware.usb.UsbManager.ACTION_USB_STATE;
+import static com.android.settings.wifi.WifiUtils.setCanShowWifiHotspotCached;
+
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
@@ -93,6 +95,7 @@ public class TetherSettingsTest {
any(String.class), anyInt(), any(UserHandle.class));
setupIsTetherAvailable(true);
+ setCanShowWifiHotspotCached(true);
when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(new String[0]);
when(mTetheringManager.getTetherableBluetoothRegexs()).thenReturn(new String[0]);
@@ -123,6 +126,16 @@ public class TetherSettingsTest {
assertThat(niks).contains(TetherSettings.KEY_WIFI_TETHER);
}
+ @Test
+ public void getNonIndexableKeys_canNotShowWifiHotspot_containsWifiTether() {
+ setCanShowWifiHotspotCached(false);
+ setupIsTetherAvailable(true);
+
+ List keys = TetherSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
+
+ assertThat(keys).contains(TetherSettings.KEY_WIFI_TETHER);
+ }
+
@Test
public void testTetherNonIndexableKeys_usbNotAvailable_usbKeyReturned() {
when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(new String[0]);
diff --git a/tests/robotests/src/com/android/settings/accounts/AvatarViewMixinTest.java b/tests/robotests/src/com/android/settings/accounts/AvatarViewMixinTest.java
index 04db5270ec780245e62730ec54ea444aa3024534..61017f71ee09e016092be0c3e4ad09e7b1e18732 100644
--- a/tests/robotests/src/com/android/settings/accounts/AvatarViewMixinTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/AvatarViewMixinTest.java
@@ -41,7 +41,6 @@ import android.os.Bundle;
import android.widget.ImageView;
import com.android.settings.homepage.SettingsHomepageActivity;
-import com.android.settings.homepage.contextualcards.slices.BatteryFixSliceTest;
import com.android.settings.testutils.shadow.ShadowUserManager;
import org.junit.Before;
@@ -95,7 +94,6 @@ public class AvatarViewMixinTest {
}
@Test
- @Config(shadows = BatteryFixSliceTest.ShadowBatteryTipLoader.class)
public void onStart_useMockAvatarViewMixin_shouldBeExecuted() {
final AvatarViewMixin mockAvatar = spy(new AvatarViewMixin(mActivity, mImageView));
diff --git a/tests/robotests/src/com/android/settings/applications/specialaccess/DataSaverControllerTest.java b/tests/robotests/src/com/android/settings/applications/specialaccess/DataSaverControllerTest.java
index 39d51fa6f50457108e67d8c79332c209d2f55ff8..ed0491085ecbf34e88cdc469679b629d26c69189 100644
--- a/tests/robotests/src/com/android/settings/applications/specialaccess/DataSaverControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/specialaccess/DataSaverControllerTest.java
@@ -18,9 +18,13 @@ package com.android.settings.applications.specialaccess;
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.when;
import static org.mockito.Mockito.spy;
import android.content.Context;
+import android.content.res.Resources;
+
+import com.android.settings.R;
import org.junit.Before;
import org.junit.Test;
@@ -34,23 +38,35 @@ import org.robolectric.annotation.Config;
public class DataSaverControllerTest {
private Context mContext;
+ private Resources mResources;
private DataSaverController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application.getApplicationContext());
+
+ mResources = spy(mContext.getResources());
+ when(mContext.getResources()).thenReturn(mResources);
+
mController = new DataSaverController(mContext, "key");
}
@Test
public void testDataSaver_byDefault_shouldBeShown() {
+ when(mResources.getBoolean(R.bool.config_show_data_saver)).thenReturn(true);
assertThat(mController.isAvailable()).isTrue();
}
@Test
@Config(qualifiers = "mcc999")
+ public void testDataSaver_ifDisabledByCarrier_shouldNotBeShown() {
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test
public void testDataSaver_ifDisabled_shouldNotBeShown() {
+ when(mResources.getBoolean(R.bool.config_show_data_saver)).thenReturn(false);
assertThat(mController.isAvailable()).isFalse();
}
}
diff --git a/tests/robotests/src/com/android/settings/applications/specialaccess/premiumsms/PremiumSmsControllerTest.java b/tests/robotests/src/com/android/settings/applications/specialaccess/premiumsms/PremiumSmsControllerTest.java
index 4c4acc719adc5febc35e52f1e78ff36494845b3c..ed4cbd1f042622827e7914182585c5882c40f6e8 100644
--- a/tests/robotests/src/com/android/settings/applications/specialaccess/premiumsms/PremiumSmsControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/specialaccess/premiumsms/PremiumSmsControllerTest.java
@@ -21,8 +21,12 @@ import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
import android.content.Context;
+import android.content.res.Resources;
+
+import com.android.settings.R;
import org.junit.Before;
import org.junit.Test;
@@ -36,23 +40,35 @@ import org.robolectric.annotation.Config;
public class PremiumSmsControllerTest {
private Context mContext;
+ private Resources mResources;
private PremiumSmsController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application.getApplicationContext());
+
+ mResources = spy(mContext.getResources());
+ when(mContext.getResources()).thenReturn(mResources);
+
mController = new PremiumSmsController(mContext, "key");
}
@Test
public void getAvailability_byDefault_shouldBeShown() {
+ when(mResources.getBoolean(R.bool.config_show_premium_sms)).thenReturn(true);
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
@Test
@Config(qualifiers = "mcc999")
+ public void getAvailability_disabledByCarrier_returnUnavailable() {
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test
public void getAvailability_disabled_returnUnavailable() {
+ when(mResources.getBoolean(R.bool.config_show_premium_sms)).thenReturn(false);
assertThat(mController.isAvailable()).isFalse();
}
}
diff --git a/tests/robotests/src/com/android/settings/applications/specialaccess/premiumsms/PremiumSmsScreenPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/specialaccess/premiumsms/PremiumSmsScreenPreferenceControllerTest.java
index 53d46cab03a629690a3a9f65f0257c6a1dafc870..5982413ac31149021ad096376e5f8db841497654 100644
--- a/tests/robotests/src/com/android/settings/applications/specialaccess/premiumsms/PremiumSmsScreenPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/specialaccess/premiumsms/PremiumSmsScreenPreferenceControllerTest.java
@@ -21,8 +21,12 @@ import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
import android.content.Context;
+import android.content.res.Resources;
+
+import com.android.settings.R;
import org.junit.Before;
import org.junit.Test;
@@ -36,23 +40,35 @@ import org.robolectric.annotation.Config;
public class PremiumSmsScreenPreferenceControllerTest {
private Context mContext;
+ private Resources mResources;
private PremiumSmsScreenPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application.getApplicationContext());
+
+ mResources = spy(mContext.getResources());
+ when(mContext.getResources()).thenReturn(mResources);
+
mController = new PremiumSmsScreenPreferenceController(mContext, "key");
}
@Test
public void getAvailability_byDefault_shouldBeShown() {
+ when(mResources.getBoolean(R.bool.config_show_premium_sms)).thenReturn(true);
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
@Test
@Config(qualifiers = "mcc999")
+ public void getAvailability_disabledByCarrier_returnUnavailable() {
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test
public void getAvailability_disabled_returnUnavailable() {
+ when(mResources.getBoolean(R.bool.config_show_premium_sms)).thenReturn(false);
assertThat(mController.isAvailable()).isFalse();
}
}
diff --git a/tests/robotests/src/com/android/settings/biometrics/combination/CombinedBiometricProfileSettingsTest.java b/tests/robotests/src/com/android/settings/biometrics/combination/CombinedBiometricProfileSettingsTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..ac8008debfae794cf11b88f4ee053ea44f741e3b
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/biometrics/combination/CombinedBiometricProfileSettingsTest.java
@@ -0,0 +1,358 @@
+/*
+ * Copyright (C) 2022 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.biometrics.combination;
+
+import static com.android.settings.biometrics.combination.BiometricsSettingsBase.CONFIRM_REQUEST;
+import static com.android.settings.password.ChooseLockPattern.RESULT_FINISHED;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+
+import android.content.Context;
+import android.content.Intent;
+import android.hardware.face.FaceManager;
+import android.hardware.fingerprint.FingerprintManager;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.XmlRes;
+import androidx.fragment.app.FragmentActivity;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceManager;
+import androidx.preference.PreferenceScreen;
+import androidx.test.core.app.ApplicationProvider;
+
+import com.android.settings.R;
+import com.android.settings.password.ChooseLockSettingsHelper;
+import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.shadow.ShadowFragment;
+import com.android.settings.testutils.shadow.ShadowSettingsPreferenceFragment;
+import com.android.settings.testutils.shadow.ShadowUtils;
+import com.android.settingslib.core.AbstractPreferenceController;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
+import org.robolectric.Robolectric;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.annotation.Config;
+import org.robolectric.util.ReflectionHelpers;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+@RunWith(RobolectricTestRunner.class)
+@Config(shadows = {ShadowSettingsPreferenceFragment.class, ShadowUtils.class, ShadowFragment.class})
+public class CombinedBiometricProfileSettingsTest {
+
+ private TestCombinedBiometricProfileSettings mFragment;
+ private Context mContext;
+
+ @Rule
+ public final MockitoRule mMockitoRule = MockitoJUnit.rule();
+ @Captor
+ private ArgumentCaptor mPreferenceCaptor;
+ @Mock
+ private FingerprintManager mFingerprintManager;
+ @Mock
+ private BiometricSettingsAppPreferenceController mBiometricSettingsAppPreferenceController;
+ @Mock
+ private FaceManager mFaceManager;
+
+ @Before
+ public void setUp() {
+ ShadowUtils.setFingerprintManager(mFingerprintManager);
+ ShadowUtils.setFaceManager(mFaceManager);
+ FakeFeatureFactory.setupForTest();
+
+ FragmentActivity activity = Robolectric.buildActivity(FragmentActivity.class,
+ new Intent().putExtra(ChooseLockSettingsHelper.EXTRA_KEY_GK_PW_HANDLE, 1L)).get();
+ mContext = spy(ApplicationProvider.getApplicationContext());
+ mFragment = spy(new TestCombinedBiometricProfileSettings(mContext));
+ doReturn(activity).when(mFragment).getActivity();
+
+ ReflectionHelpers.setField(mFragment, "mDashboardFeatureProvider",
+ FakeFeatureFactory.setupForTest().dashboardFeatureProvider);
+
+ final Map, List> preferenceControllers =
+ ReflectionHelpers.getField(mFragment, "mPreferenceControllers");
+ List controllerList = new ArrayList<>();
+ controllerList.add(mBiometricSettingsAppPreferenceController);
+ preferenceControllers.put(BiometricSettingsAppPreferenceController.class, controllerList);
+
+ doAnswer(invocation -> {
+ final CharSequence key = invocation.getArgument(0);
+ final Preference preference = new Preference(mContext);
+ preference.setKey(key.toString());
+ return preference;
+ }).when(mFragment).findPreference(any());
+ }
+
+ @Test
+ public void testClickFingerprintUnlockWithValidGkPwHandle() {
+ doAnswer(invocation -> {
+ final FingerprintManager.GenerateChallengeCallback callback =
+ invocation.getArgument(1);
+ callback.onChallengeGenerated(0, 0, 1L);
+ return null;
+ }).when(mFingerprintManager).generateChallenge(anyInt(), any());
+ doReturn(new byte[] { 1 }).when(mFragment).requestGatekeeperHat(any(), anyLong(), anyInt(),
+ anyLong());
+
+ // Start fragment
+ mFragment.onAttach(mContext);
+ mFragment.onCreate(null);
+ mFragment.onCreateView(LayoutInflater.from(mContext), mock(ViewGroup.class), Bundle.EMPTY);
+ mFragment.onResume();
+
+ // User clicks on "Fingerprint Unlock"
+ final Preference preference = new Preference(mContext);
+ preference.setKey(mFragment.getFingerprintPreferenceKey());
+ mFragment.onPreferenceTreeClick(preference);
+
+ verify(mBiometricSettingsAppPreferenceController).handlePreferenceTreeClick(
+ mPreferenceCaptor.capture());
+ List capturedPreferences = mPreferenceCaptor.getAllValues();
+
+ assertThat(capturedPreferences.size()).isEqualTo(1);
+ assertThat(capturedPreferences.get(0).getKey())
+ .isEqualTo(mFragment.getFingerprintPreferenceKey());
+ }
+
+ @Test
+ public void testClickFingerprintUnlockIfGkPwHandleTimeout() {
+ doAnswer(invocation -> {
+ final FingerprintManager.GenerateChallengeCallback callback =
+ invocation.getArgument(1);
+ callback.onChallengeGenerated(0, 0, 1L);
+ return null;
+ }).when(mFingerprintManager).generateChallenge(anyInt(), any());
+ doThrow(new IllegalStateException("Test")).when(mFragment).requestGatekeeperHat(any(),
+ anyLong(), anyInt(), anyLong());
+
+ // Start fragment
+ mFragment.onAttach(mContext);
+ mFragment.onCreate(null);
+ mFragment.onCreateView(LayoutInflater.from(mContext), mock(ViewGroup.class), Bundle.EMPTY);
+ mFragment.onResume();
+
+ // User clicks on "Fingerprint Unlock"
+ final Preference preference = new Preference(mContext);
+ preference.setKey(mFragment.getFingerprintPreferenceKey());
+ mFragment.onPreferenceTreeClick(preference);
+
+ verify(mFragment).launchChooseOrConfirmLock();
+ }
+
+ @Test
+ public void testActivityResultLaunchFingerprintUnlock() {
+ doAnswer(invocation -> {
+ final FingerprintManager.GenerateChallengeCallback callback =
+ invocation.getArgument(1);
+ callback.onChallengeGenerated(0, 0, 1L);
+ return null;
+ }).when(mFingerprintManager).generateChallenge(anyInt(), any());
+ doReturn(new byte[] { 1 }).when(mFragment).requestGatekeeperHat(any(), anyLong(), anyInt(),
+ anyLong());
+
+ // Start fragment
+ mFragment.onAttach(mContext);
+ final Bundle bundle = new Bundle();
+ bundle.putString(BiometricsSettingsBase.RETRY_PREFERENCE_KEY,
+ mFragment.getFingerprintPreferenceKey());
+ final Bundle retryBundle = new Bundle();
+ bundle.putBundle(BiometricsSettingsBase.RETRY_PREFERENCE_BUNDLE, retryBundle);
+ mFragment.onCreate(bundle);
+ mFragment.onCreateView(LayoutInflater.from(mContext), mock(ViewGroup.class), Bundle.EMPTY);
+ mFragment.onResume();
+
+ // onActivityResult
+ mFragment.onActivityResult(CONFIRM_REQUEST, RESULT_FINISHED,
+ new Intent().putExtra(ChooseLockSettingsHelper.EXTRA_KEY_GK_PW_HANDLE, 1L));
+
+ verify(mBiometricSettingsAppPreferenceController).handlePreferenceTreeClick(
+ mPreferenceCaptor.capture());
+ List capturedPreferences = mPreferenceCaptor.getAllValues();
+ assertThat(capturedPreferences.size()).isEqualTo(1);
+ assertThat(capturedPreferences.get(0).getKey())
+ .isEqualTo(mFragment.getFingerprintPreferenceKey());
+ }
+
+ @Test
+ public void testClickFaceUnlock() {
+ doAnswer(invocation -> {
+ final FaceManager.GenerateChallengeCallback callback =
+ invocation.getArgument(1);
+ callback.onGenerateChallengeResult(0, 0, 1L);
+ return null;
+ }).when(mFaceManager).generateChallenge(anyInt(), any());
+ doReturn(new byte[] { 1 }).when(mFragment).requestGatekeeperHat(any(), anyLong(), anyInt(),
+ anyLong());
+
+ // Start fragment
+ mFragment.onAttach(mContext);
+ mFragment.onCreate(null);
+ mFragment.onCreateView(LayoutInflater.from(mContext), mock(ViewGroup.class), Bundle.EMPTY);
+ mFragment.onResume();
+
+ // User clicks on "Face Unlock"
+ final Preference preference = new Preference(mContext);
+ preference.setKey(mFragment.getFacePreferenceKey());
+ mFragment.onPreferenceTreeClick(preference);
+
+ verify(mBiometricSettingsAppPreferenceController).handlePreferenceTreeClick(
+ mPreferenceCaptor.capture());
+ List capturedPreferences = mPreferenceCaptor.getAllValues();
+ assertThat(capturedPreferences.size()).isEqualTo(1);
+ assertThat(capturedPreferences.get(0).getKey()).isEqualTo(mFragment.getFacePreferenceKey());
+ }
+
+ @Test
+ public void testClickFaceUnlockIfGkPwHandleTimeout() {
+ doAnswer(invocation -> {
+ final FaceManager.GenerateChallengeCallback callback =
+ invocation.getArgument(1);
+ callback.onGenerateChallengeResult(0, 0, 1L);
+ return null;
+ }).when(mFaceManager).generateChallenge(anyInt(), any());
+ doThrow(new IllegalStateException("Test")).when(mFragment).requestGatekeeperHat(any(),
+ anyLong(), anyInt(), anyLong());
+
+ // Start fragment
+ mFragment.onAttach(mContext);
+ mFragment.onCreate(null);
+ mFragment.onCreateView(LayoutInflater.from(mContext), mock(ViewGroup.class), Bundle.EMPTY);
+ mFragment.onResume();
+
+ // User clicks on "Face Unlock"
+ final Preference preference = new Preference(mContext);
+ preference.setKey(mFragment.getFacePreferenceKey());
+ mFragment.onPreferenceTreeClick(preference);
+
+ verify(mFragment).launchChooseOrConfirmLock();
+ }
+
+ @Test
+ public void testActivityResultLaunchFaceUnlock() {
+ doAnswer(invocation -> {
+ final FaceManager.GenerateChallengeCallback callback =
+ invocation.getArgument(1);
+ callback.onGenerateChallengeResult(0, 0, 1L);
+ return null;
+ }).when(mFaceManager).generateChallenge(anyInt(), any());
+ doReturn(new byte[] { 1 }).when(mFragment).requestGatekeeperHat(any(), anyLong(), anyInt(),
+ anyLong());
+
+ // Start fragment
+ mFragment.onAttach(mContext);
+ final Bundle bundle = new Bundle();
+ bundle.putString(BiometricsSettingsBase.RETRY_PREFERENCE_KEY,
+ mFragment.getFingerprintPreferenceKey());
+ final Bundle retryBundle = new Bundle();
+ bundle.putBundle(BiometricsSettingsBase.RETRY_PREFERENCE_BUNDLE, retryBundle);
+ mFragment.onCreate(bundle);
+ mFragment.onCreateView(LayoutInflater.from(mContext), mock(ViewGroup.class), Bundle.EMPTY);
+ mFragment.onResume();
+
+ // User clicks on "Face Unlock"
+ final Preference preference = new Preference(mContext);
+ preference.setKey(mFragment.getFacePreferenceKey());
+ mFragment.onPreferenceTreeClick(preference);
+
+ verify(mBiometricSettingsAppPreferenceController).handlePreferenceTreeClick(
+ mPreferenceCaptor.capture());
+ List capturedPreferences = mPreferenceCaptor.getAllValues();
+ assertThat(capturedPreferences.size()).isEqualTo(1);
+ assertThat(capturedPreferences.get(0).getKey()).isEqualTo(mFragment.getFacePreferenceKey());
+ }
+
+ /**
+ * a test fragment that initializes PreferenceScreen for testing.
+ */
+ static class TestCombinedBiometricProfileSettings extends CombinedBiometricProfileSettings {
+
+ private final Context mContext;
+ private final PreferenceManager mPreferenceManager;
+
+ TestCombinedBiometricProfileSettings(Context context) {
+ super();
+ mContext = context;
+ mPreferenceManager = new PreferenceManager(context);
+ mPreferenceManager.setPreferences(mPreferenceManager.createPreferenceScreen(context));
+ setArguments(new Bundle());
+ }
+
+ @Override
+ public int getMetricsCategory() {
+ return 0;
+ }
+
+ @Override
+ public int getPreferenceScreenResId() {
+ return R.xml.placeholder_prefs;
+ }
+
+ @Override
+ public PreferenceScreen getPreferenceScreen() {
+ return mPreferenceManager.getPreferenceScreen();
+ }
+
+ @Override
+ public PreferenceManager getPreferenceManager() {
+ return mPreferenceManager;
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
+ // do nothing
+ }
+
+ @Override
+ public void addPreferencesFromResource(@XmlRes int preferencesResId) {
+ // do nothing
+ }
+
+ @Override
+ public Context getContext() {
+ return mContext;
+ }
+
+ @Override
+ protected void launchChooseOrConfirmLock() {
+ // do nothing
+ }
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/biometrics/face/FaceSettingsLockscreenBypassPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/biometrics/face/FaceSettingsLockscreenBypassPreferenceControllerTest.java
index b9692cf06d210b89d5236e4558f53245c0dae903..77a6b02d71b164c0787d2b57110e4cdb415d4400 100644
--- a/tests/robotests/src/com/android/settings/biometrics/face/FaceSettingsLockscreenBypassPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/biometrics/face/FaceSettingsLockscreenBypassPreferenceControllerTest.java
@@ -31,6 +31,7 @@ import android.hardware.face.FaceManager;
import android.os.UserManager;
import android.provider.Settings;
+import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.shadow.ShadowUtils;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import com.android.settingslib.RestrictedSwitchPreference;
@@ -65,6 +66,9 @@ public class FaceSettingsLockscreenBypassPreferenceControllerTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ ShadowUtils.setFaceManager(mFaceManager);
+ FakeFeatureFactory.setupForTest();
+
mContext = spy(RuntimeEnvironment.application);
when(mContext.getSystemService(eq(Context.FACE_SERVICE))).thenReturn(mFaceManager);
when(mContext.getPackageManager()).thenReturn(mPackageManager);
diff --git a/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrollingTest.java b/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrollingTest.java
index b8083198e68cbad8ce669a429e8baa1f0e946a11..ee6ae223169c252628099f591c5159fda6e1f477 100644
--- a/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrollingTest.java
+++ b/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrollingTest.java
@@ -50,7 +50,6 @@ import android.os.CancellationSignal;
import android.os.Vibrator;
import android.view.Display;
import android.view.Surface;
-import android.widget.TextView;
import com.android.settings.R;
import com.android.settings.testutils.FakeFeatureFactory;
@@ -59,7 +58,6 @@ import com.android.settings.widget.RingProgressBar;
import com.airbnb.lottie.LottieAnimationView;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
@@ -99,19 +97,6 @@ public class FingerprintEnrollEnrollingTest {
FakeFeatureFactory.setupForTest();
}
- @Test
- @Ignore
- public void fingerprintEnrollHelp_shouldShowHelpText() {
- EnrollmentCallback enrollmentCallback = verifyAndCaptureEnrollmentCallback();
-
- enrollmentCallback.onEnrollmentProgress(123);
- enrollmentCallback.onEnrollmentHelp(
- FingerprintManager.FINGERPRINT_ERROR_UNABLE_TO_PROCESS, "test enrollment help");
-
- TextView errorText = mActivity.findViewById(R.id.error_text);
- assertThat(errorText.getText()).isEqualTo("test enrollment help");
- }
-
@Test
public void fingerprintUdfpsEnrollSuccessProgress_shouldNotVibrate() {
initializeActivityFor(TYPE_UDFPS_OPTICAL);
@@ -150,6 +135,16 @@ public class FingerprintEnrollEnrollingTest {
verify(mActivity, never()).onCancelEnrollment(anyInt());
}
+ @Test
+ public void fingerprintUdfpsOverlayEnrollment_loseFocusWithCancelFlag_shouldNotCancelAgain() {
+ initializeActivityFor(TYPE_UDFPS_OPTICAL);
+
+ mActivity.mIsCanceled = true;
+ mActivity.onWindowFocusChanged(true);
+
+ verify(mActivity, never()).onCancelEnrollment(anyInt());
+ }
+
@Test
public void fingerprintSfpsEnroll_PlaysAllAnimationsAssetsCorrectly() {
initializeActivityFor(TYPE_POWER_BUTTON);
diff --git a/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintSettingsRequireScreenOnToAuthPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintSettingsRequireScreenOnToAuthPreferenceControllerTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..ff74d59782af20250e6d94355d56410ec033fd65
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintSettingsRequireScreenOnToAuthPreferenceControllerTest.java
@@ -0,0 +1,149 @@
+/*
+ * Copyright (C) 2022 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.biometrics.fingerprint;
+
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.DISABLED_DEPENDENT_SETTING;
+import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.hardware.fingerprint.FingerprintManager;
+import android.provider.Settings;
+
+import com.android.settings.testutils.shadow.ShadowUtils;
+import com.android.settingslib.RestrictedSwitchPreference;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.util.ReflectionHelpers;
+
+@RunWith(RobolectricTestRunner.class)
+@Config(shadows = {ShadowUtils.class})
+public class FingerprintSettingsRequireScreenOnToAuthPreferenceControllerTest {
+
+ @Mock
+ private FingerprintManager mFingerprintManager;
+ @Mock
+ private PackageManager mPackageManager;
+ @Mock
+ private RestrictedSwitchPreference mPreference;
+
+ private Context mContext;
+ private FingerprintSettingsRequireScreenOnToAuthPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
+ when(mContext.getSystemService(eq(Context.FINGERPRINT_SERVICE))).thenReturn(
+ mFingerprintManager);
+ when(mContext.getPackageManager()).thenReturn(mPackageManager);
+
+ mController = spy(new FingerprintSettingsRequireScreenOnToAuthPreferenceController(mContext,
+ "test_key"));
+ ReflectionHelpers.setField(mController, "mFingerprintManager", mFingerprintManager);
+ }
+
+ @After
+ public void tearDown() {
+ ShadowUtils.reset();
+ }
+
+ @Test
+ public void onPreferenceChange_settingIsUpdated() {
+ boolean state = Settings.Secure.getInt(mContext.getContentResolver(),
+ Settings.Secure.SFPS_REQUIRE_SCREEN_ON_TO_AUTH_ENABLED, 1) != 0;
+
+ assertThat(mController.isChecked()).isFalse();
+ assertThat(mController.onPreferenceChange(mPreference, !state)).isTrue();
+ boolean newState = Settings.Secure.getInt(mContext.getContentResolver(),
+ Settings.Secure.SFPS_REQUIRE_SCREEN_ON_TO_AUTH_ENABLED, 1) != 0;
+ assertThat(newState).isEqualTo(!state);
+ }
+
+ @Test
+ public void isAvailable_isEnabled_whenSfpsHardwareDetected_AndHasEnrolledFingerprints() {
+ assertThat(mController.isAvailable()).isEqualTo(false);
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
+ configure_hardwareDetected_isSfps_hasEnrolledTemplates(
+ true /* isHardwareDetected */,
+ true /* isPowerbuttonFps */,
+ true /* hasEnrolledTemplates */);
+ assertThat(mController.isAvailable()).isEqualTo(true);
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+ }
+
+ @Test
+ public void isAvailable_isDisabled_whenSfpsHardwareDetected_AndNoEnrolledFingerprints() {
+ assertThat(mController.isAvailable()).isEqualTo(false);
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
+ configure_hardwareDetected_isSfps_hasEnrolledTemplates(
+ true /* isHardwareDetected */,
+ true /* isPowerbuttonFps */,
+ false /* hasEnrolledTemplates */);
+ assertThat(mController.isAvailable()).isEqualTo(true);
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
+ }
+
+ @Test
+ public void isUnavailable_whenHardwareNotDetected() {
+ assertThat(mController.isAvailable()).isFalse();
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
+ configure_hardwareDetected_isSfps_hasEnrolledTemplates(
+ false /* isHardwareDetected */,
+ true /* isPowerbuttonFps */,
+ true /* hasEnrolledTemplates */);
+ assertThat(mController.isAvailable()).isFalse();
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
+ }
+
+ @Test
+ public void isUnavailable_onNonSfpsDevice() {
+ assertThat(mController.isAvailable()).isFalse();
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
+ configure_hardwareDetected_isSfps_hasEnrolledTemplates(
+ true /* isHardwareDetected */,
+ false /* isPowerbuttonFps */,
+ true /* hasEnrolledTemplates */);
+ assertThat(mController.isAvailable()).isFalse();
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
+ }
+
+ private void configure_hardwareDetected_isSfps_hasEnrolledTemplates(
+ boolean isHardwareDetected, boolean isPowerbuttonFps, boolean hasEnrolledTemplates) {
+ when(mFingerprintManager.isHardwareDetected()).thenReturn(isHardwareDetected);
+ when(mFingerprintManager.isPowerbuttonFps()).thenReturn(isPowerbuttonFps);
+ when(mFingerprintManager.hasEnrolledTemplates(anyInt())).thenReturn(hasEnrolledTemplates);
+ }
+
+
+}
diff --git a/tests/robotests/src/com/android/settings/biometrics/fingerprint/MessageDisplayControllerTest.java b/tests/robotests/src/com/android/settings/biometrics/fingerprint/MessageDisplayControllerTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..0fa0918d90ac7dc6878e4cb3830feac4778a3cb8
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/biometrics/fingerprint/MessageDisplayControllerTest.java
@@ -0,0 +1,219 @@
+/*
+ * Copyright (C) 2022 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.biometrics.fingerprint;
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
+
+import android.hardware.fingerprint.FingerprintManager;
+import android.os.Handler;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.shadows.ShadowLooper;
+
+import java.time.Clock;
+import java.util.concurrent.TimeUnit;
+
+@RunWith(RobolectricTestRunner.class)
+public class MessageDisplayControllerTest {
+ @Rule
+ public final MockitoRule mockito = MockitoJUnit.rule();
+
+ private static final long START_TIME = 0L;
+ private static final int HELP_ID = 0;
+ private static final String HELP_MESSAGE = "Default Help Message";
+ private static final int REMAINING = 5;
+ private static final int HELP_MINIMUM_DISPLAY_TIME = 300;
+ private static final int PROGRESS_MINIMUM_DISPLAY_TIME = 250;
+ private static final int COLLECT_TIME = 100;
+
+ private MessageDisplayController mMessageDisplayController;
+ @Mock
+ private FingerprintManager.EnrollmentCallback mEnrollmentCallback;
+ @Mock
+ private Clock mClock;
+
+ @Before
+ public void setup() {
+ mMessageDisplayController = new MessageDisplayController(new Handler(), mEnrollmentCallback,
+ mClock,
+ HELP_MINIMUM_DISPLAY_TIME, /* progressPriorityOverHelp */
+ PROGRESS_MINIMUM_DISPLAY_TIME, /* prioritizeAcquireMessages */
+ false, false, COLLECT_TIME);
+ }
+
+ private void setMessageDisplayController(boolean progressPriorityOverHelp,
+ boolean prioritizeAcquireMessages) {
+ mMessageDisplayController = new MessageDisplayController(new Handler(), mEnrollmentCallback,
+ mClock, HELP_MINIMUM_DISPLAY_TIME, PROGRESS_MINIMUM_DISPLAY_TIME,
+ progressPriorityOverHelp, prioritizeAcquireMessages, COLLECT_TIME);
+ }
+
+ @Test
+ public void showsHelpMessageAfterCollectTime() {
+ when(mClock.millis()).thenReturn(START_TIME);
+
+ mMessageDisplayController.onEnrollmentHelp(HELP_ID, HELP_MESSAGE);
+ when(mClock.millis()).thenReturn((long) COLLECT_TIME);
+ ShadowLooper.idleMainLooper(COLLECT_TIME, TimeUnit.MILLISECONDS);
+
+ verify(mEnrollmentCallback).onEnrollmentHelp(HELP_ID, HELP_MESSAGE);
+ verifyNoMoreInteractions(mEnrollmentCallback);
+ }
+
+ @Test
+ public void showsProgressMessageAfterCollectTime() {
+ when(mClock.millis()).thenReturn(START_TIME);
+
+ mMessageDisplayController.onEnrollmentProgress(REMAINING);
+ when(mClock.millis()).thenReturn((long) COLLECT_TIME);
+ ShadowLooper.idleMainLooper(COLLECT_TIME, TimeUnit.MILLISECONDS);
+
+ verify(mEnrollmentCallback).onEnrollmentProgress(REMAINING);
+ verifyNoMoreInteractions(mEnrollmentCallback);
+ }
+
+ @Test
+ public void helpDisplayedForMinimumDisplayTime() {
+ when(mClock.millis()).thenReturn(START_TIME);
+
+ mMessageDisplayController.onEnrollmentHelp(HELP_ID, HELP_MESSAGE);
+ when(mClock.millis()).thenReturn((long) COLLECT_TIME);
+ ShadowLooper.idleMainLooper(COLLECT_TIME, TimeUnit.MILLISECONDS);
+
+ verify(mEnrollmentCallback).onEnrollmentHelp(HELP_ID, HELP_MESSAGE);
+
+ mMessageDisplayController.onEnrollmentProgress(REMAINING);
+
+ verifyNoMoreInteractions(mEnrollmentCallback);
+
+ when(mClock.millis()).thenReturn((long) (HELP_MINIMUM_DISPLAY_TIME + COLLECT_TIME));
+ ShadowLooper.idleMainLooper(HELP_MINIMUM_DISPLAY_TIME, TimeUnit.MILLISECONDS);
+
+ verify(mEnrollmentCallback).onEnrollmentProgress(REMAINING);
+ }
+
+ @Test
+ public void progressDisplayedForMinimumDisplayTime() {
+ when(mClock.millis()).thenReturn(START_TIME);
+
+ mMessageDisplayController.onEnrollmentProgress(REMAINING);
+ when(mClock.millis()).thenReturn((long) COLLECT_TIME);
+ ShadowLooper.idleMainLooper(COLLECT_TIME, TimeUnit.MILLISECONDS);
+
+ verify(mEnrollmentCallback).onEnrollmentProgress(REMAINING);
+
+ mMessageDisplayController.onEnrollmentHelp(HELP_ID, HELP_MESSAGE);
+
+ verifyNoMoreInteractions(mEnrollmentCallback);
+
+ when(mClock.millis()).thenReturn((long) (COLLECT_TIME + PROGRESS_MINIMUM_DISPLAY_TIME));
+ ShadowLooper.idleMainLooper(PROGRESS_MINIMUM_DISPLAY_TIME, TimeUnit.MILLISECONDS);
+
+ verify(mEnrollmentCallback).onEnrollmentHelp(HELP_ID, HELP_MESSAGE);
+ }
+
+ @Test
+ public void prioritizeHelpMessage_thenShowProgress() {
+ when(mClock.millis()).thenReturn(START_TIME);
+
+ mMessageDisplayController.onEnrollmentProgress(REMAINING);
+ mMessageDisplayController.onEnrollmentHelp(HELP_ID, HELP_MESSAGE);
+ when(mClock.millis()).thenReturn((long) COLLECT_TIME);
+ ShadowLooper.idleMainLooper(COLLECT_TIME, TimeUnit.MILLISECONDS);
+
+ verify(mEnrollmentCallback).onEnrollmentHelp(HELP_ID, HELP_MESSAGE);
+ verifyNoMoreInteractions(mEnrollmentCallback);
+
+ mMessageDisplayController.onEnrollmentHelp(HELP_ID, HELP_MESSAGE);
+ when(mClock.millis()).thenReturn((long) (COLLECT_TIME + HELP_MINIMUM_DISPLAY_TIME));
+ ShadowLooper.idleMainLooper(HELP_MINIMUM_DISPLAY_TIME, TimeUnit.MILLISECONDS);
+
+ verify(mEnrollmentCallback).onEnrollmentProgress(REMAINING);
+ }
+
+ @Test
+ public void prioritizeProgressOverHelp() {
+ when(mClock.millis()).thenReturn(START_TIME);
+ setMessageDisplayController(true /* progressPriorityOverHelp */,
+ false /* prioritizeAcquireMessages */);
+
+ mMessageDisplayController.onEnrollmentProgress(REMAINING);
+ mMessageDisplayController.onEnrollmentHelp(HELP_ID, HELP_MESSAGE);
+ when(mClock.millis()).thenReturn((long) COLLECT_TIME);
+ ShadowLooper.idleMainLooper(COLLECT_TIME, TimeUnit.MILLISECONDS);
+
+ verify(mEnrollmentCallback).onEnrollmentProgress(REMAINING);
+ verifyNoMoreInteractions(mEnrollmentCallback);
+ }
+
+ @Test
+ public void prioritizeHelpMessageByCount() {
+ String newHelpMessage = "New message";
+ when(mClock.millis()).thenReturn(START_TIME);
+ setMessageDisplayController(false /* progressPriorityOverHelp */,
+ true /* prioritizeAcquireMessages */);
+
+ mMessageDisplayController.onEnrollmentHelp(HELP_ID, HELP_MESSAGE);
+ mMessageDisplayController.onEnrollmentHelp(HELP_ID, HELP_MESSAGE);
+ mMessageDisplayController.onEnrollmentHelp(HELP_ID, newHelpMessage);
+ when(mClock.millis()).thenReturn((long) COLLECT_TIME);
+ ShadowLooper.idleMainLooper(COLLECT_TIME, TimeUnit.MILLISECONDS);
+
+ verify(mEnrollmentCallback).onEnrollmentHelp(HELP_ID, HELP_MESSAGE);
+ verifyNoMoreInteractions(mEnrollmentCallback);
+ }
+
+ @Test
+ public void ignoreSameProgress() {
+ int progressChange = REMAINING - 1;
+ when(mClock.millis()).thenReturn(START_TIME);
+ setMessageDisplayController(true /* progressPriorityOverHelp */,
+ false /* prioritizeAcquireMessages */);
+
+ mMessageDisplayController.onEnrollmentProgress(REMAINING);
+ mMessageDisplayController.onEnrollmentHelp(HELP_ID, HELP_MESSAGE);
+ when(mClock.millis()).thenReturn((long) COLLECT_TIME);
+ ShadowLooper.idleMainLooper(COLLECT_TIME, TimeUnit.MILLISECONDS);
+
+ verify(mEnrollmentCallback).onEnrollmentProgress(REMAINING);
+ verifyNoMoreInteractions(mEnrollmentCallback);
+
+ mMessageDisplayController.onEnrollmentProgress(REMAINING);
+ mMessageDisplayController.onEnrollmentHelp(HELP_ID, HELP_MESSAGE);
+ when(mClock.millis()).thenReturn((long) (COLLECT_TIME + PROGRESS_MINIMUM_DISPLAY_TIME));
+ ShadowLooper.idleMainLooper(PROGRESS_MINIMUM_DISPLAY_TIME, TimeUnit.MILLISECONDS);
+
+ verify(mEnrollmentCallback).onEnrollmentHelp(HELP_ID, HELP_MESSAGE);
+
+ mMessageDisplayController.onEnrollmentProgress(progressChange);
+ mMessageDisplayController.onEnrollmentHelp(HELP_ID, HELP_MESSAGE);
+ when(mClock.millis()).thenReturn((long) (COLLECT_TIME + PROGRESS_MINIMUM_DISPLAY_TIME
+ + HELP_MINIMUM_DISPLAY_TIME));
+ ShadowLooper.idleMainLooper(HELP_MINIMUM_DISPLAY_TIME, TimeUnit.MILLISECONDS);
+
+ verify(mEnrollmentCallback).onEnrollmentProgress(progressChange);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothSwitchPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothSwitchPreferenceControllerTest.java
index 3c5a91d218878bbb8ddf50da064c5ffa7c40f21d..50c82d3c0d82601f93731eef771b7423e3f81c03 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothSwitchPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothSwitchPreferenceControllerTest.java
@@ -18,13 +18,14 @@ package com.android.settings.bluetooth;
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import android.content.Context;
import android.provider.Settings;
-
import android.text.TextUtils;
+
import com.android.settings.R;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.utils.AnnotationSpan;
@@ -109,16 +110,34 @@ public class BluetoothSwitchPreferenceControllerTest {
}
@Test
- public void onStart_shouldStartAlwaysDiscoverable() {
+ public void onStart_setAlwaysDiscoverableAsTrue_shouldStartAlwaysDiscoverable() {
+ mController.setAlwaysDiscoverable(true);
mController.onStart();
verify(mAlwaysDiscoverable).start();
}
@Test
- public void onStop_shouldStopAlwaysDiscoverable() {
+ public void onStart_setAlwaysDiscoverableAsFalse_shouldStartAlwaysDiscoverable() {
+ mController.setAlwaysDiscoverable(false);
+ mController.onStart();
+
+ verify(mAlwaysDiscoverable, never()).start();
+ }
+
+ @Test
+ public void onStop_setAlwaysDiscoverableAsTrue_shouldStopAlwaysDiscoverable() {
+ mController.setAlwaysDiscoverable(true);
mController.onStop();
verify(mAlwaysDiscoverable).stop();
}
+
+ @Test
+ public void onStop__setAlwaysDiscoverableAsFalse_shouldStopAlwaysDiscoverable() {
+ mController.setAlwaysDiscoverable(false);
+ mController.onStop();
+
+ verify(mAlwaysDiscoverable, never()).stop();
+ }
}
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/BluetoothDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/connecteddevice/BluetoothDashboardFragmentTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..2aa2fa8e8dfd23a7b2900fb9d0b3588e8cfca8b3
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/connecteddevice/BluetoothDashboardFragmentTest.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2022 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.connecteddevice;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(RobolectricTestRunner.class)
+public class BluetoothDashboardFragmentTest {
+ private static final String SETTINGS_PACKAGE_NAME = "com.android.settings";
+ private static final String SYSTEMUI_PACKAGE_NAME = "com.android.systemui";
+ private static final String SLICE_ACTION = "com.android.settings.SEARCH_RESULT_TRAMPOLINE";
+ private static final String TEST_APP_NAME = "com.testapp.settings";
+ private static final String TEST_ACTION = "com.testapp.settings.ACTION_START";
+
+ private BluetoothDashboardFragment mFragment;
+
+ @Before
+ public void setUp() {
+ mFragment = new BluetoothDashboardFragment();
+ }
+
+
+ @Test
+ public void isAlwaysDiscoverable_callingAppIsNotFromSystemApp_returnsFalse() {
+ assertThat(mFragment.isAlwaysDiscoverable(TEST_APP_NAME, TEST_ACTION)).isFalse();
+ }
+
+ @Test
+ public void isAlwaysDiscoverable_callingAppIsFromSettings_returnsTrue() {
+ assertThat(mFragment.isAlwaysDiscoverable(SETTINGS_PACKAGE_NAME, TEST_ACTION)).isTrue();
+ }
+
+ @Test
+ public void isAlwaysDiscoverable_callingAppIsFromSystemUI_returnsTrue() {
+ assertThat(mFragment.isAlwaysDiscoverable(SYSTEMUI_PACKAGE_NAME, TEST_ACTION)).isTrue();
+ }
+
+ @Test
+ public void isAlwaysDiscoverable_actionIsFromSlice_returnsFalse() {
+ assertThat(mFragment.isAlwaysDiscoverable(SYSTEMUI_PACKAGE_NAME, SLICE_ACTION)).isFalse();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/datausage/AppDataUsageTest.java b/tests/robotests/src/com/android/settings/datausage/AppDataUsageTest.java
index 47db4f2950648066e1fc38a160ccbdb5bf5dd00f..e7b59a35fe556cdb3ad02bbead8352a57bf22c47 100644
--- a/tests/robotests/src/com/android/settings/datausage/AppDataUsageTest.java
+++ b/tests/robotests/src/com/android/settings/datausage/AppDataUsageTest.java
@@ -110,7 +110,10 @@ public class AppDataUsageTest {
@Test
@Config(shadows = ShadowFragment.class)
public void onCreate_appUid_shouldGetAppLabelFromAppInfo() throws NameNotFoundException {
- mFragment = spy(new AppDataUsage());
+ mFragment = spy(new AppDataUsage() {
+ @Override
+ public boolean isSimHardwareVisible(Context context) { return true; }
+ });
final FragmentActivity activity = spy(Robolectric.setupActivity(FragmentActivity.class));
doReturn(mPackageManager).when(activity).getPackageManager();
doReturn(activity).when(mFragment).getActivity();
@@ -140,7 +143,10 @@ public class AppDataUsageTest {
@Test
@Config(shadows = ShadowFragment.class)
public void onCreate_notAppUid_shouldGetAppLabelFromUidDetailProvider() {
- mFragment = spy(new AppDataUsage());
+ mFragment = spy(new AppDataUsage() {
+ @Override
+ public boolean isSimHardwareVisible(Context context) { return true; }
+ });
ReflectionHelpers.setField(mFragment, "mDashboardFeatureProvider",
FakeFeatureFactory.setupForTest().dashboardFeatureProvider);
doReturn(Robolectric.setupActivity(FragmentActivity.class)).when(mFragment).getActivity();
@@ -167,7 +173,10 @@ public class AppDataUsageTest {
@Test
public void bindAppHeader_allWorkApps_shouldNotShowAppInfoLink() {
- mFragment = spy(new AppDataUsage());
+ mFragment = spy(new AppDataUsage() {
+ @Override
+ public boolean isSimHardwareVisible(Context context) { return true; }
+ });
when(mFragment.getPreferenceManager())
.thenReturn(mock(PreferenceManager.class, RETURNS_DEEP_STUBS));
@@ -184,7 +193,10 @@ public class AppDataUsageTest {
throws PackageManager.NameNotFoundException {
final int fakeUserId = 100;
- mFragment = spy(new AppDataUsage());
+ mFragment = spy(new AppDataUsage() {
+ @Override
+ public boolean isSimHardwareVisible(Context context) { return true; }
+ });
final ArraySet packages = new ArraySet<>();
packages.add("pkg");
final AppItem appItem = new AppItem(123456789);
@@ -210,7 +222,10 @@ public class AppDataUsageTest {
@Test
public void changePreference_backgroundData_shouldUpdateUI() {
- mFragment = spy(new AppDataUsage());
+ mFragment = spy(new AppDataUsage() {
+ @Override
+ public boolean isSimHardwareVisible(Context context) { return true; }
+ });
final AppItem appItem = new AppItem(123456789);
final RestrictedSwitchPreference pref = mock(RestrictedSwitchPreference.class);
final DataSaverBackend dataSaverBackend = mock(DataSaverBackend.class);
@@ -227,7 +242,10 @@ public class AppDataUsageTest {
@Test
public void updatePrefs_restrictedByAdmin_shouldDisablePreference() {
- mFragment = spy(new AppDataUsage());
+ mFragment = spy(new AppDataUsage() {
+ @Override
+ public boolean isSimHardwareVisible(Context context) { return true; }
+ });
final int testUid = 123123;
final AppItem appItem = new AppItem(testUid);
final RestrictedSwitchPreference restrictBackgroundPref
@@ -255,7 +273,10 @@ public class AppDataUsageTest {
@Test
public void bindData_noAppUsageData_shouldHideCycleSpinner() {
- mFragment = spy(new AppDataUsage());
+ mFragment = spy(new AppDataUsage() {
+ @Override
+ public boolean isSimHardwareVisible(Context context) { return true; }
+ });
final SpinnerPreference cycle = mock(SpinnerPreference.class);
ReflectionHelpers.setField(mFragment, "mCycle", cycle);
final Preference preference = mock(Preference.class);
@@ -271,7 +292,10 @@ public class AppDataUsageTest {
@Test
public void bindData_hasAppUsageData_shouldShowCycleSpinnerAndUpdateUsageSummary() {
- mFragment = spy(new AppDataUsage());
+ mFragment = spy(new AppDataUsage() {
+ @Override
+ public boolean isSimHardwareVisible(Context context) { return true; }
+ });
final Context context = RuntimeEnvironment.application;
ReflectionHelpers.setField(mFragment, "mContext", context);
final long backgroundBytes = 1234L;
@@ -300,7 +324,10 @@ public class AppDataUsageTest {
@Test
public void onCreateLoader_categoryApp_shouldQueryDataUsageUsingAppKey() {
- mFragment = new AppDataUsage();
+ mFragment = new AppDataUsage() {
+ @Override
+ public boolean isSimHardwareVisible(Context context) { return true; }
+ };
final Context context = RuntimeEnvironment.application;
final int testUid = 123123;
final AppItem appItem = new AppItem(testUid);
@@ -323,7 +350,10 @@ public class AppDataUsageTest {
@Test
public void onCreateLoader_categoryUser_shouldQueryDataUsageUsingAssociatedUids() {
- mFragment = new AppDataUsage();
+ mFragment = new AppDataUsage() {
+ @Override
+ public boolean isSimHardwareVisible(Context context) { return true; }
+ };
final Context context = RuntimeEnvironment.application;
final int testUserId = 11;
final AppItem appItem = new AppItem(testUserId);
@@ -360,7 +390,10 @@ public class AppDataUsageTest {
appItem.category = AppItem.CATEGORY_APP;
appItem.addUid(uid);
- mFragment = new AppDataUsage();
+ mFragment = new AppDataUsage() {
+ @Override
+ public boolean isSimHardwareVisible(Context context) { return true; }
+ };
ReflectionHelpers.setField(mFragment, "mContext", RuntimeEnvironment.application);
ReflectionHelpers.setField(mFragment, "mCycles", testCycles);
ReflectionHelpers.setField(mFragment, "mAppItem", appItem);
@@ -393,7 +426,10 @@ public class AppDataUsageTest {
builder.setStartTime(tenDaysAgo).setEndTime(now).setTotalUsage(1234L);
data.add(builder.build());
- mFragment = new AppDataUsage();
+ mFragment = new AppDataUsage() {
+ @Override
+ public boolean isSimHardwareVisible(Context context) { return true; }
+ };
ReflectionHelpers.setField(mFragment, "mContext", RuntimeEnvironment.application);
ReflectionHelpers.setField(mFragment, "mCycleAdapter", mock(CycleAdapter.class));
ReflectionHelpers.setField(mFragment, "mSelectedCycle", tenDaysAgo);
@@ -420,7 +456,10 @@ public class AppDataUsageTest {
ShadowDataUsageUtils.HAS_SIM = false;
ShadowSubscriptionManager.setDefaultDataSubscriptionId(
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
- mFragment = spy(new AppDataUsage());
+ mFragment = spy(new AppDataUsage() {
+ @Override
+ public boolean isSimHardwareVisible(Context context) { return true; }
+ });
doReturn(Robolectric.setupActivity(FragmentActivity.class)).when(mFragment).getActivity();
doReturn(RuntimeEnvironment.application).when(mFragment).getContext();
final UidDetailProvider uidDetailProvider = mock(UidDetailProvider.class);
diff --git a/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java b/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java
index 6d1081416dd6a5d0ebe4affadc468f7db544e4c5..68d49fc6352f428b7c6b56c2f1ae1c86314f73e8 100644
--- a/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java
+++ b/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java
@@ -29,12 +29,15 @@ import static org.mockito.Mockito.verify;
import android.app.usage.NetworkStatsManager;
import android.content.Context;
+import android.content.res.Resources;
import android.net.NetworkPolicyManager;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import androidx.fragment.app.FragmentActivity;
+import com.android.settings.R;
+
import com.android.settings.testutils.shadow.ShadowDashboardFragment;
import com.android.settings.testutils.shadow.ShadowDataUsageUtils;
import com.android.settings.testutils.shadow.ShadowUserManager;
@@ -70,6 +73,7 @@ public class DataUsageSummaryTest {
private NetworkStatsManager mNetworkStatsManager;
private TelephonyManager mTelephonyManager;
private Context mContext;
+ private Resources mResources;
private FragmentActivity mActivity;
/**
@@ -84,13 +88,18 @@ public class DataUsageSummaryTest {
ShadowUserManager.getShadow().setIsAdminUser(true);
shadowContext.setSystemService(Context.NETWORK_POLICY_SERVICE, mNetworkPolicyManager);
- mContext = RuntimeEnvironment.application;
+ mContext = spy(RuntimeEnvironment.application);
mTelephonyManager = mContext.getSystemService(TelephonyManager.class);
final ShadowTelephonyManager shadowTelephonyManager = Shadows.shadowOf(mTelephonyManager);
shadowTelephonyManager.setTelephonyManagerForSubscriptionId(
SubscriptionManager.INVALID_SUBSCRIPTION_ID, mTelephonyManager);
shadowTelephonyManager.setTelephonyManagerForSubscriptionId(1, mTelephonyManager);
mActivity = spy(Robolectric.buildActivity(FragmentActivity.class).get());
+
+ mResources = spy(mContext.getResources());
+ doReturn(mResources).when(mContext).getResources();
+ doReturn(true).when(mResources).getBoolean(R.bool.config_show_sim_info);
+
doReturn(mNetworkStatsManager).when(mActivity).getSystemService(NetworkStatsManager.class);
}
diff --git a/tests/robotests/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceControllerTest.java
index 72477b94585936dc7f1d5a8a73b43e6befab403b..7ab311fe2abd9fdccc842573074c914a484b641d 100644
--- a/tests/robotests/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceControllerTest.java
@@ -24,9 +24,9 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.when;
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothManager;
import android.content.Context;
-import android.content.pm.PackageManager;
-import android.content.res.Resources;
import android.os.SystemProperties;
@@ -54,6 +54,11 @@ public class BluetoothMaxConnectedAudioDevicesPreferenceControllerTest {
@Spy
private Context mSpyContext = RuntimeEnvironment.application;
+ @Mock
+ private BluetoothManager mBluetoothManager;
+ @Mock
+ private BluetoothAdapter mBluetoothAdapter;
+
private ListPreference mPreference;
private BluetoothMaxConnectedAudioDevicesPreferenceController mController;
@@ -63,19 +68,15 @@ public class BluetoothMaxConnectedAudioDevicesPreferenceControllerTest {
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
+ doReturn(mBluetoothManager).when(mSpyContext).getSystemService(BluetoothManager.class);
+ doReturn(mBluetoothAdapter).when(mBluetoothManager).getAdapter();
// Get XML values without mock
// Setup test list preference using XML values
mPreference = new ListPreference(mSpyContext);
mPreference.setEntries(R.array.bluetooth_max_connected_audio_devices);
mPreference.setEntryValues(R.array.bluetooth_max_connected_audio_devices_values);
- // Retrieve default max connected audio devices to a test controlled value
- try {
- Resources res = mSpyContext.getPackageManager().getResourcesForApplication("com.android.bluetooth");
- TEST_MAX_CONNECTED_AUDIO_DEVICES = res.getInteger(res.getIdentifier("config_bluetooth_max_connected_audio_devices", "integer", "com.android.bluetooth"));
- } catch (PackageManager.NameNotFoundException e) {
- e.printStackTrace();
- }
-
+ doReturn(TEST_MAX_CONNECTED_AUDIO_DEVICES).when(mBluetoothAdapter)
+ .getMaxConnectedAudioDevices();
// Init the actual controller
mController = new BluetoothMaxConnectedAudioDevicesPreferenceController(mSpyContext);
// Construct preference in the controller via a mocked preference screen object
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceControllerTest.java
index 55194add83db1d9bd6862f9b778e22a1e5592185..bae629ced4265d38431bb70b8a8ebfb4e60cafb4 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceControllerTest.java
@@ -29,6 +29,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
+import android.content.res.Resources;
import android.os.UserManager;
import android.telephony.TelephonyManager;
@@ -69,12 +70,18 @@ public class ImeiInfoPreferenceControllerTest {
private PreferenceCategory mCategory;
private Context mContext;
+ private Resources mResources;
private ImeiInfoPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
+
+ mResources = spy(mContext.getResources());
+ when(mContext.getResources()).thenReturn(mResources);
+ when(mResources.getBoolean(R.bool.config_show_sim_info)).thenReturn(true);
+
doReturn(mUserManager).when(mContext).getSystemService(UserManager.class);
mController = spy(new ImeiInfoPreferenceController(mContext, "imei_info"));
mController.setHost(mFragment);
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/simstatus/SimStatusPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/simstatus/SimStatusPreferenceControllerTest.java
index 85a6fac765ace141afae5919504cb5bad94ba111..4ffaf7ae6ec861d7096f79eade49c7b0554a22e6 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/simstatus/SimStatusPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/simstatus/SimStatusPreferenceControllerTest.java
@@ -25,6 +25,7 @@ import static org.mockito.Mockito.when;
import android.content.Context;
import android.os.UserManager;
+import android.content.res.Resources;
import android.telephony.TelephonyManager;
import androidx.fragment.app.Fragment;
@@ -64,12 +65,18 @@ public class SimStatusPreferenceControllerTest {
private PreferenceCategory mCategory;
private Context mContext;
+ private Resources mResources;
private SimStatusPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
+
+ mResources = spy(mContext.getResources());
+ when(mContext.getResources()).thenReturn(mResources);
+ when(mResources.getBoolean(R.bool.config_show_sim_info)).thenReturn(true);
+
doReturn(mUserManager).when(mContext).getSystemService(UserManager.class);
mController = spy(new SimStatusPreferenceController(mContext, mFragment));
doReturn(true).when(mController).isAvailable();
diff --git a/tests/robotests/src/com/android/settings/display/ControlsTrivialPrivacyPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/ControlsTrivialPrivacyPreferenceControllerTest.java
index 3d4bc2e1933bab3bd97825a62851fcf769528b6e..8bb3ff69001058fbb556fcb783f0ca4d97d6e004 100644
--- a/tests/robotests/src/com/android/settings/display/ControlsTrivialPrivacyPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/ControlsTrivialPrivacyPreferenceControllerTest.java
@@ -21,10 +21,14 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import android.content.ContentResolver;
import android.content.Context;
+import android.database.Cursor;
+import android.database.MatrixCursor;
import android.provider.Settings;
import androidx.preference.Preference;
@@ -40,6 +44,7 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
+import org.mockito.stubbing.Answer;
import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class)
@@ -62,9 +67,11 @@ public class ControlsTrivialPrivacyPreferenceControllerTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mContext = ApplicationProvider.getApplicationContext();
+ mContext = spy(ApplicationProvider.getApplicationContext());
+ mContentResolver = spy(mContext.getContentResolver());
+ when(mContext.getContentResolver()).thenReturn(mContentResolver);
- mContentResolver = mContext.getContentResolver();
+ setCustomizableLockScreenQuickAffordancesEnabled(false);
mController = new ControlsTrivialPrivacyPreferenceController(mContext, TEST_KEY);
}
@@ -130,6 +137,18 @@ public class ControlsTrivialPrivacyPreferenceControllerTest {
verify(mPreference, atLeastOnce()).setSummary(mController.getSummary());
}
+ @Test
+ public void updateStateWithCustomizableLockScreenQuickAffordancesEnabled() {
+ setCustomizableLockScreenQuickAffordancesEnabled(true);
+ Settings.Secure.putInt(mContentResolver, DEPENDENCY_SETTING_KEY, 0);
+
+ mController.updateState(mPreference);
+
+ verify(mPreference).setEnabled(true);
+ verify(mPreference, atLeastOnce()).setSummary(
+ mContext.getString(R.string.lockscreen_trivial_controls_summary));
+ }
+
@Test
public void getAvailabilityStatusWithoutDeviceControls() {
Settings.Secure.putInt(mContentResolver, DEPENDENCY_SETTING_KEY, 0);
@@ -138,6 +157,15 @@ public class ControlsTrivialPrivacyPreferenceControllerTest {
BasePreferenceController.DISABLED_DEPENDENT_SETTING);
}
+ @Test
+ public void getAvailabilityStatusWithCustomizableLockScreenQuickAffordancesEnabled() {
+ setCustomizableLockScreenQuickAffordancesEnabled(true);
+ Settings.Secure.putInt(mContentResolver, DEPENDENCY_SETTING_KEY, 0);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(
+ BasePreferenceController.AVAILABLE);
+ }
+
@Test
public void getAvailabilityStatusWithDeviceControls() {
Settings.Secure.putInt(mContentResolver, DEPENDENCY_SETTING_KEY, 1);
@@ -154,4 +182,22 @@ public class ControlsTrivialPrivacyPreferenceControllerTest {
mController.displayPreference(mPreferenceScreen);
verify(mPreference).setDependency(anyString());
}
+
+ private void setCustomizableLockScreenQuickAffordancesEnabled(boolean isEnabled) {
+ when(
+ mContentResolver.query(
+ CustomizableLockScreenUtils.FLAGS_URI, null, null, null))
+ .thenAnswer((Answer) invocation -> {
+ final MatrixCursor cursor = new MatrixCursor(
+ new String[] {
+ CustomizableLockScreenUtils.NAME,
+ CustomizableLockScreenUtils.VALUE
+ });
+ cursor.addRow(
+ new Object[] {
+ CustomizableLockScreenUtils.ENABLED_FLAG, isEnabled ? 1 : 0
+ });
+ return cursor;
+ });
+ }
}
diff --git a/tests/robotests/src/com/android/settings/display/CustomizableLockScreenQuickAffordancesPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/CustomizableLockScreenQuickAffordancesPreferenceControllerTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..4ad5c22e3458f7b47a240bdad4bfe3cd7b4b7bf7
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/display/CustomizableLockScreenQuickAffordancesPreferenceControllerTest.java
@@ -0,0 +1,155 @@
+/*
+ * Copyright (C) 2022 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 static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.Intent;
+import android.database.MatrixCursor;
+import android.text.TextUtils;
+
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+import androidx.test.core.app.ApplicationProvider;
+import androidx.test.filters.SmallTest;
+
+import com.android.settings.R;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+
+@SmallTest
+@RunWith(RobolectricTestRunner.class)
+public class CustomizableLockScreenQuickAffordancesPreferenceControllerTest {
+
+ private static final String KEY = "key";
+
+ @Mock private Context mContext;
+ @Mock private ContentResolver mContentResolver;
+
+ private CustomizableLockScreenQuickAffordancesPreferenceController mUnderTest;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ when(mContext.getContentResolver()).thenReturn(mContentResolver);
+ when(mContext.getResources())
+ .thenReturn(ApplicationProvider.getApplicationContext().getResources());
+
+ mUnderTest = new CustomizableLockScreenQuickAffordancesPreferenceController(mContext, KEY);
+ }
+
+ @Test
+ public void getAvailabilityStatus_whenEnabled() {
+ setEnabled(true);
+
+ assertThat(mUnderTest.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_whenNotEnabled() {
+ setEnabled(false);
+
+ assertThat(mUnderTest.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
+ }
+
+ @Test
+ public void displayPreference_click() {
+ setSelectedAffordanceNames("one", "two");
+ final PreferenceScreen screen = mock(PreferenceScreen.class);
+ final Preference preference = mock(Preference.class);
+ when(screen.findPreference(KEY)).thenReturn(preference);
+
+ mUnderTest.displayPreference(screen);
+
+ final ArgumentCaptor clickCaptor =
+ ArgumentCaptor.forClass(Preference.OnPreferenceClickListener.class);
+ verify(preference).setOnPreferenceClickListener(clickCaptor.capture());
+
+ clickCaptor.getValue().onPreferenceClick(preference);
+
+ final ArgumentCaptor intentCaptor = ArgumentCaptor.forClass(Intent.class);
+ verify(preference).setOnPreferenceClickListener(clickCaptor.capture());
+ verify(mContext).startActivity(intentCaptor.capture());
+ assertThat(intentCaptor.getValue().getPackage()).isEqualTo(
+ mContext.getString(R.string.config_wallpaper_picker_package));
+ assertThat(intentCaptor.getValue().getAction()).isEqualTo(Intent.ACTION_SET_WALLPAPER);
+ assertThat(intentCaptor.getValue().getStringExtra("destination"))
+ .isEqualTo("quick_affordances");
+ }
+
+ @Test
+ public void getSummary_whenNoneAreSelected() {
+ setSelectedAffordanceNames();
+
+ assertThat(mUnderTest.getSummary()).isNull();
+ }
+
+ @Test
+ public void getSummary_whenOneIsSelected() {
+ setSelectedAffordanceNames("one");
+
+ assertThat(TextUtils.equals(mUnderTest.getSummary(), "one")).isTrue();
+ }
+
+ @Test
+ public void getSummary_whenTwoAreSelected() {
+ setSelectedAffordanceNames("one", "two");
+
+ assertThat(TextUtils.equals(mUnderTest.getSummary(), "one, two")).isTrue();
+ }
+
+ private void setEnabled(boolean isEnabled) {
+ final MatrixCursor cursor = new MatrixCursor(
+ new String[] {
+ CustomizableLockScreenUtils.NAME,
+ CustomizableLockScreenUtils.VALUE
+ });
+ cursor.addRow(new Object[] { CustomizableLockScreenUtils.ENABLED_FLAG, isEnabled ? 1 : 0 });
+ when(
+ mContentResolver.query(
+ CustomizableLockScreenUtils.FLAGS_URI, null, null, null))
+ .thenReturn(cursor);
+ }
+
+ private void setSelectedAffordanceNames(String... affordanceNames) {
+ final MatrixCursor cursor = new MatrixCursor(
+ new String[] { CustomizableLockScreenUtils.AFFORDANCE_NAME });
+ for (final String name : affordanceNames) {
+ cursor.addRow(new Object[] { name });
+ }
+
+ when(
+ mContentResolver.query(
+ CustomizableLockScreenUtils.SELECTIONS_URI, null, null, null))
+ .thenReturn(cursor);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/display/SmartAutoRotatePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/SmartAutoRotatePreferenceControllerTest.java
index 39fdb04922855b067113430e77d269c3c5abfd0b..0e7a86f5eab343bc4e1b71ee483b5de178e8a17d 100644
--- a/tests/robotests/src/com/android/settings/display/SmartAutoRotatePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/SmartAutoRotatePreferenceControllerTest.java
@@ -80,6 +80,9 @@ public class SmartAutoRotatePreferenceControllerTest {
when(mContext.getResources()).thenReturn(mResources);
when(mContext.getContentResolver()).thenReturn(mContentResolver);
+ when(mResources.getBoolean(R.bool.config_auto_rotate_face_detection_available)).thenReturn(
+ true);
+
doReturn(PACKAGE_NAME).when(mPackageManager).getRotationResolverPackageName();
doReturn(PackageManager.PERMISSION_GRANTED).when(mPackageManager).checkPermission(
Manifest.permission.CAMERA, PACKAGE_NAME);
diff --git a/tests/robotests/src/com/android/settings/display/SmartAutoRotatePreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/display/SmartAutoRotatePreferenceFragmentTest.java
index e537419668157bbd2ef629e2826911153b59ffd9..a25702bd2eac105758341f5644b587bced9f4746 100644
--- a/tests/robotests/src/com/android/settings/display/SmartAutoRotatePreferenceFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/display/SmartAutoRotatePreferenceFragmentTest.java
@@ -111,6 +111,8 @@ public class SmartAutoRotatePreferenceFragmentTest {
when(mActivity.getPackageManager()).thenReturn(mPackageManager);
when(mFragment.getActivity()).thenReturn(mActivity);
when(mFragment.getContext()).thenReturn(mContext);
+ when(mActivity.getResources()).thenReturn(mResources);
+
doReturn(mView).when(mFragment).getView();
when(mFragment.findPreference(AUTO_ROTATE_SWITCH_PREFERENCE_KEY)).thenReturn(
@@ -152,6 +154,17 @@ public class SmartAutoRotatePreferenceFragmentTest {
verify(mRotateSwitchPreference, never()).setVisible(false);
}
+ @Test
+ public void createHeader_faceDetectionNotEnabledByConfig_switchBarIsDisabled() {
+ doReturn(false).when(mResources).getBoolean(
+ R.bool.config_auto_rotate_face_detection_available);
+
+ mFragment.createHeader(mActivity);
+
+ verify(mRotateMainSwitchPreference, times(1)).setVisible(false);
+ verify(mRotateSwitchPreference, never()).setVisible(false);
+ }
+
@Test
public void createPreferenceControllers_noSettableDeviceStates_returnsEmptyList() {
enableDeviceStateSettableRotationStates(new String[]{}, new String[]{});
@@ -198,6 +211,8 @@ public class SmartAutoRotatePreferenceFragmentTest {
when(mResources.getStringArray(
R.array.config_settableAutoRotationDeviceStatesDescriptions)).thenReturn(
settableStatesDescriptions);
+ when(mResources.getBoolean(R.bool.config_auto_rotate_face_detection_available)).thenReturn(
+ true);
DeviceStateRotationLockSettingsManager.resetInstance();
DeviceStateRotationLockSettingsManager.getInstance(mContext)
.resetStateForTesting(mResources);
diff --git a/tests/robotests/src/com/android/settings/dream/DreamSettingsTest.java b/tests/robotests/src/com/android/settings/dream/DreamSettingsTest.java
index a5545645e9b6a60cc35b5329286f6454cf637a37..4fceb17e3722bcf7b74c5e7a0016eaec4d428eb4 100644
--- a/tests/robotests/src/com/android/settings/dream/DreamSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/dream/DreamSettingsTest.java
@@ -18,6 +18,8 @@ package com.android.settings.dream;
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -29,33 +31,40 @@ import com.android.settingslib.dream.DreamBackend.WhenToDream;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
import java.util.Arrays;
import java.util.List;
-import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class)
public class DreamSettingsTest {
private static final List KEYS = Arrays.asList(
- DreamSettings.WHILE_CHARGING_ONLY,
- DreamSettings.WHILE_DOCKED_ONLY,
- DreamSettings.EITHER_CHARGING_OR_DOCKED,
- DreamSettings.NEVER_DREAM
+ DreamSettings.WHILE_CHARGING_ONLY,
+ DreamSettings.WHILE_DOCKED_ONLY,
+ DreamSettings.EITHER_CHARGING_OR_DOCKED,
+ DreamSettings.NEVER_DREAM
);
private static final @WhenToDream int[] SETTINGS = {
- DreamBackend.WHILE_CHARGING,
- DreamBackend.WHILE_DOCKED,
- DreamBackend.EITHER,
- DreamBackend.NEVER,
+ DreamBackend.WHILE_CHARGING,
+ DreamBackend.WHILE_DOCKED,
+ DreamBackend.EITHER,
+ DreamBackend.NEVER,
};
private static final int[] RES_IDS = {
- R.string.screensaver_settings_summary_sleep,
- R.string.screensaver_settings_summary_dock,
- R.string.screensaver_settings_summary_either_long,
- R.string.screensaver_settings_summary_never
+ R.string.screensaver_settings_summary_sleep,
+ R.string.screensaver_settings_summary_dock,
+ R.string.screensaver_settings_summary_either_long,
+ R.string.screensaver_settings_summary_never
+ };
+
+ private static final int[] RES_IDS_NO_BATTERY = {
+ R.string.screensaver_settings_summary_sleep,
+ R.string.screensaver_settings_summary_dock_and_charging,
+ R.string.screensaver_settings_summary_either_long,
+ R.string.screensaver_settings_summary_never
};
@Test
@@ -81,33 +90,44 @@ public class DreamSettingsTest {
@Test
public void getDreamSettingDescriptionResId() {
for (int i = 0; i < SETTINGS.length; i++) {
- assertThat(DreamSettings.getDreamSettingDescriptionResId(SETTINGS[i]))
+ assertThat(DreamSettings.getDreamSettingDescriptionResId(
+ SETTINGS[i], /* enabledOnBattery= */ false))
+ .isEqualTo(RES_IDS_NO_BATTERY[i]);
+ assertThat(DreamSettings.getDreamSettingDescriptionResId(
+ SETTINGS[i], /* enabledOnBattery= */ true))
.isEqualTo(RES_IDS[i]);
}
// Default
- assertThat(DreamSettings.getDreamSettingDescriptionResId(-1))
+ assertThat(DreamSettings.getDreamSettingDescriptionResId(-1, /* enabledOnBattery= */ false))
+ .isEqualTo(R.string.screensaver_settings_summary_never);
+ assertThat(DreamSettings.getDreamSettingDescriptionResId(-1, /* enabledOnBattery= */ true))
.isEqualTo(R.string.screensaver_settings_summary_never);
}
@Test
public void summaryText_whenDreamsAreOff() {
- DreamBackend mockBackend = mock(DreamBackend.class);
- Context mockContext = mock(Context.class);
+ final String fakeSummaryOff = "test dream off";
+ final DreamBackend mockBackend = mock(DreamBackend.class);
+ final Context mockContext = mock(Context.class);
when(mockBackend.isEnabled()).thenReturn(false);
+ when(mockContext.getString(R.string.screensaver_settings_summary_off)).thenReturn(
+ fakeSummaryOff);
- assertThat(DreamSettings.getSummaryTextFromBackend(mockBackend, mockContext))
- .isEqualTo(mockContext.getString(R.string.screensaver_settings_summary_off));
+ assertThat(DreamSettings.getSummaryTextFromBackend(mockBackend, mockContext)).isEqualTo(
+ fakeSummaryOff);
}
@Test
public void summaryTest_WhenDreamsAreOn() {
final String fakeName = "test_name";
- DreamBackend mockBackend = mock(DreamBackend.class);
- Context mockContext = mock(Context.class);
+ final DreamBackend mockBackend = mock(DreamBackend.class);
+ final Context mockContext = mock(Context.class);
when(mockBackend.isEnabled()).thenReturn(true);
when(mockBackend.getActiveDreamName()).thenReturn(fakeName);
+ when(mockContext.getString(eq(R.string.screensaver_settings_summary_on), anyString()))
+ .thenAnswer(i -> i.getArgument(1) + " test dream is on");
- assertThat(DreamSettings.getSummaryTextFromBackend(mockBackend, mockContext))
- .isEqualTo(fakeName);
+ assertThat(DreamSettings.getSummaryTextFromBackend(mockBackend, mockContext)).isEqualTo(
+ fakeName + " test dream is on");
}
}
diff --git a/tests/robotests/src/com/android/settings/dream/WhenToDreamPickerTest.java b/tests/robotests/src/com/android/settings/dream/WhenToDreamPickerTest.java
index 16f8599f2f117adaa582d1b2e8a47cc668255b6f..91ec2993893f5d55caf9ab41d3ee02a350a31ec3 100644
--- a/tests/robotests/src/com/android/settings/dream/WhenToDreamPickerTest.java
+++ b/tests/robotests/src/com/android/settings/dream/WhenToDreamPickerTest.java
@@ -28,6 +28,7 @@ import android.os.UserManager;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.android.settingslib.dream.DreamBackend;
import org.junit.Before;
@@ -37,9 +38,11 @@ import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
+import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
@RunWith(RobolectricTestRunner.class)
+@Config(shadows = SettingsShadowResources.class)
public class WhenToDreamPickerTest {
private WhenToDreamPicker mPicker;
@@ -53,10 +56,15 @@ public class WhenToDreamPickerTest {
MockitoAnnotations.initMocks(this);
final Context context = spy(ApplicationProvider.getApplicationContext());
+ SettingsShadowResources.overrideResource(
+ com.android.internal.R.bool.config_dreamsEnabledOnBattery,
+ true);
+
when(context.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
FakeFeatureFactory.setupForTest();
- mPicker = new WhenToDreamPicker();
+ mPicker = spy(new WhenToDreamPicker());
+ when(mPicker.getContext()).thenReturn(context);
mPicker.onAttach(context);
ReflectionHelpers.setField(mPicker, "mBackend", mBackend);
diff --git a/tests/robotests/src/com/android/settings/dream/WhenToDreamPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/dream/WhenToDreamPreferenceControllerTest.java
index 3305cded8ad793e637297f03f04de49a3b378dfd..6e687bba7d9fb9abebf631d11a2aad0d070ec430 100644
--- a/tests/robotests/src/com/android/settings/dream/WhenToDreamPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/dream/WhenToDreamPreferenceControllerTest.java
@@ -16,15 +16,24 @@
package com.android.settings.dream;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.anyInt;
+import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.os.PowerManager;
import androidx.preference.Preference;
import androidx.test.core.app.ApplicationProvider;
+import com.android.settings.R;
+import com.android.settings.display.AmbientDisplayAlwaysOnPreferenceController;
import com.android.settingslib.dream.DreamBackend;
import com.android.settingslib.dream.DreamBackend.WhenToDream;
@@ -38,32 +47,64 @@ import org.robolectric.util.ReflectionHelpers;
@RunWith(RobolectricTestRunner.class)
public class WhenToDreamPreferenceControllerTest {
+ private static final String TEST_PACKAGE = "com.android.test";
private WhenToDreamPreferenceController mController;
private Context mContext;
@Mock
private DreamBackend mBackend;
+ @Mock
+ private PowerManager mPowerManager;
+ @Mock
+ private PackageManager mPackageManager;
+ @Mock
+ private ApplicationInfo mApplicationInfo;
@Before
- public void setup() {
+ public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
- mContext = ApplicationProvider.getApplicationContext();
- mController = new WhenToDreamPreferenceController(mContext);
+ mContext = spy(ApplicationProvider.getApplicationContext());
+ mController = new WhenToDreamPreferenceController(mContext, true, true);
ReflectionHelpers.setField(mController, "mBackend", mBackend);
+ when(mContext.getSystemService(PowerManager.class)).thenReturn(mPowerManager);
+ when(mPowerManager.isAmbientDisplaySuppressedForTokenByApp(anyString(), anyInt()))
+ .thenReturn(false);
+
+ mApplicationInfo.uid = 1;
+ when(mContext.getString(
+ com.android.internal.R.string.config_defaultWellbeingPackage)).thenReturn(
+ TEST_PACKAGE);
+
+ when(mContext.getPackageManager()).thenReturn(mPackageManager);
+ when(mPackageManager.getApplicationInfo(TEST_PACKAGE, /* flag= */ 0)).thenReturn(
+ mApplicationInfo);
}
@Test
- public void updateSummary() {
+ public void testUpdateSummary() {
// Don't have to test the other settings because DreamSettings tests that all
// @WhenToDream values map to the correct ResId
final @WhenToDream int testSetting = DreamBackend.WHILE_CHARGING;
final Preference mockPref = mock(Preference.class);
when(mockPref.getContext()).thenReturn(mContext);
when(mBackend.getWhenToDreamSetting()).thenReturn(testSetting);
- final String expectedString =
- mContext.getString(DreamSettings.getDreamSettingDescriptionResId(testSetting));
+ final int expectedResId = DreamSettings.getDreamSettingDescriptionResId(testSetting, true);
+
+ mController.updateState(mockPref);
+ verify(mockPref).setSummary(expectedResId);
+ }
+
+ @Test
+ public void testBedtimeModeSuppression() {
+ final Preference mockPref = mock(Preference.class);
+ when(mockPref.getContext()).thenReturn(mContext);
+ when(mBackend.getWhenToDreamSetting()).thenReturn(DreamBackend.WHILE_CHARGING);
+ when(mPowerManager.isAmbientDisplaySuppressedForTokenByApp(anyString(), anyInt()))
+ .thenReturn(true);
+
+ assertTrue(AmbientDisplayAlwaysOnPreferenceController.isAodSuppressedByBedtime(mContext));
mController.updateState(mockPref);
- verify(mockPref).setSummary(expectedString);
+ verify(mockPref).setSummary(R.string.screensaver_settings_when_to_dream_bedtime);
}
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
index 5db76b1797b479da929a8a4866836adba6b7d68e..8c650868836968475485f7bab151d735390dea6b 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
@@ -434,8 +434,7 @@ public class AdvancedPowerUsageDetailTest {
ArgumentCaptor captor = ArgumentCaptor.forClass(CharSequence.class);
verify(mEntityHeaderController).setSummary(captor.capture());
- assertThat(captor.getValue().toString())
- .isEqualTo("No usage from last full charge");
+ assertThat(captor.getValue().toString()).isEmpty();
}
@Test
@@ -467,7 +466,7 @@ public class AdvancedPowerUsageDetailTest {
ArgumentCaptor captor = ArgumentCaptor.forClass(CharSequence.class);
verify(mEntityHeaderController).setSummary(captor.capture());
assertThat(captor.getValue().toString())
- .isEqualTo("2 min background from last full charge");
+ .isEqualTo("2 min background since last full charge");
}
@Test
@@ -485,7 +484,7 @@ public class AdvancedPowerUsageDetailTest {
ArgumentCaptor captor = ArgumentCaptor.forClass(CharSequence.class);
verify(mEntityHeaderController).setSummary(captor.capture());
assertThat(captor.getValue().toString())
- .isEqualTo("Background less than a minute from last full charge");
+ .isEqualTo("Background less than a minute since last full charge");
}
@Test
@@ -504,7 +503,7 @@ public class AdvancedPowerUsageDetailTest {
ArgumentCaptor captor = ArgumentCaptor.forClass(CharSequence.class);
verify(mEntityHeaderController).setSummary(captor.capture());
assertThat(captor.getValue().toString())
- .isEqualTo("Total less than a minute from last full charge");
+ .isEqualTo("Total less than a minute since last full charge");
}
@Test
@@ -520,8 +519,8 @@ public class AdvancedPowerUsageDetailTest {
ArgumentCaptor captor = ArgumentCaptor.forClass(CharSequence.class);
verify(mEntityHeaderController).setSummary(captor.capture());
- assertThat(captor.getValue().toString())
- .isEqualTo("1 min total • background less than a minute\nfrom last full charge");
+ assertThat(captor.getValue().toString()).isEqualTo(
+ "1 min total • background less than a minute\nsince last full charge");
}
@Test
@@ -538,7 +537,7 @@ public class AdvancedPowerUsageDetailTest {
ArgumentCaptor captor = ArgumentCaptor.forClass(CharSequence.class);
verify(mEntityHeaderController).setSummary(captor.capture());
assertThat(captor.getValue().toString())
- .isEqualTo("1 min total from last full charge");
+ .isEqualTo("1 min total since last full charge");
}
@Test
@@ -555,7 +554,7 @@ public class AdvancedPowerUsageDetailTest {
ArgumentCaptor captor = ArgumentCaptor.forClass(CharSequence.class);
verify(mEntityHeaderController).setSummary(captor.capture());
assertThat(captor.getValue().toString())
- .isEqualTo("6 min total • 4 min background\nfrom last full charge");
+ .isEqualTo("6 min total • 4 min background\nsince last full charge");
}
@Test
@@ -742,7 +741,8 @@ public class AdvancedPowerUsageDetailTest {
public void startBatteryDetailPage_noBatteryUsage_hasBasicData() {
final ArgumentCaptor captor = ArgumentCaptor.forClass(Intent.class);
- AdvancedPowerUsageDetail.startBatteryDetailPage(mActivity, mFragment, PACKAGE_NAME[0]);
+ AdvancedPowerUsageDetail.startBatteryDetailPage(
+ mActivity, mFragment, PACKAGE_NAME[0], UserHandle.OWNER);
verify(mActivity).startActivity(captor.capture());
@@ -760,7 +760,8 @@ public class AdvancedPowerUsageDetailTest {
PackageManager.NameNotFoundException {
doReturn(UID).when(mPackageManager).getPackageUid(PACKAGE_NAME[0], 0 /* no flag */);
- AdvancedPowerUsageDetail.startBatteryDetailPage(mActivity, mFragment, PACKAGE_NAME[0]);
+ AdvancedPowerUsageDetail.startBatteryDetailPage(
+ mActivity, mFragment, PACKAGE_NAME[0], UserHandle.OWNER);
assertThat(mBundle.getInt(AdvancedPowerUsageDetail.EXTRA_UID)).isEqualTo(UID);
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.java
index d4469301894237e856274f5ade94a90aa5a3fc5d..79bd84bd1ec6b2909c6a6595facad256b0152164 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.java
@@ -33,7 +33,6 @@ import android.os.BatteryManager;
import android.os.PowerManager;
import com.android.settings.Utils;
-import com.android.settings.homepage.contextualcards.slices.BatteryFixSliceTest;
import org.junit.Before;
import org.junit.Test;
@@ -42,7 +41,6 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
-import org.robolectric.annotation.Config;
@RunWith(RobolectricTestRunner.class)
public class BatteryBroadcastReceiverTest {
@@ -57,6 +55,7 @@ public class BatteryBroadcastReceiverTest {
private BatteryBroadcastReceiver mBatteryBroadcastReceiver;
private Context mContext;
private Intent mChargingIntent;
+ private Intent mDockDefenderBypassIntent;
@Before
public void setUp() {
@@ -74,12 +73,11 @@ public class BatteryBroadcastReceiverTest {
mChargingIntent.putExtra(BatteryManager.EXTRA_SCALE, BATTERY_INTENT_SCALE);
mChargingIntent
.putExtra(BatteryManager.EXTRA_STATUS, BatteryManager.BATTERY_STATUS_CHARGING);
+ mDockDefenderBypassIntent = new Intent(BatteryUtils.BYPASS_DOCK_DEFENDER_ACTION);
+
}
@Test
- @Config(shadows = {
- BatteryFixSliceTest.ShadowBatteryTipLoader.class
- })
public void testOnReceive_batteryLevelChanged_dataUpdated() {
mBatteryBroadcastReceiver.onReceive(mContext, mChargingIntent);
@@ -91,9 +89,6 @@ public class BatteryBroadcastReceiverTest {
}
@Test
- @Config(shadows = {
- BatteryFixSliceTest.ShadowBatteryTipLoader.class
- })
public void testOnReceive_batteryHealthChanged_dataUpdated() {
mChargingIntent
.putExtra(BatteryManager.EXTRA_HEALTH, BatteryManager.BATTERY_HEALTH_OVERHEAT);
@@ -105,9 +100,6 @@ public class BatteryBroadcastReceiverTest {
}
@Test
- @Config(shadows = {
- BatteryFixSliceTest.ShadowBatteryTipLoader.class
- })
public void onReceive_batteryNotPresent_shouldShowHelpMessage() {
mChargingIntent.putExtra(BatteryManager.EXTRA_PRESENT, false);
@@ -117,9 +109,6 @@ public class BatteryBroadcastReceiverTest {
}
@Test
- @Config(shadows = {
- BatteryFixSliceTest.ShadowBatteryTipLoader.class
- })
public void testOnReceive_powerSaveModeChanged_listenerInvoked() {
mBatteryBroadcastReceiver.onReceive(mContext,
new Intent(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED));
@@ -128,9 +117,6 @@ public class BatteryBroadcastReceiverTest {
}
@Test
- @Config(shadows = {
- BatteryFixSliceTest.ShadowBatteryTipLoader.class
- })
public void testOnReceive_batteryDataNotChanged_listenerNotInvoked() {
final String batteryLevel = Utils.getBatteryPercentage(mChargingIntent);
final String batteryStatus =
@@ -148,9 +134,13 @@ public class BatteryBroadcastReceiverTest {
}
@Test
- @Config(shadows = {
- BatteryFixSliceTest.ShadowBatteryTipLoader.class
- })
+ public void testOnReceive_dockDefenderBypassed_listenerInvoked() {
+ mBatteryBroadcastReceiver.onReceive(mContext, mDockDefenderBypassIntent);
+
+ verify(mBatteryListener).onBatteryChanged(BatteryUpdateType.BATTERY_STATUS);
+ }
+
+ @Test
public void testRegister_updateBatteryStatus() {
doReturn(mChargingIntent).when(mContext).registerReceiver(any(), any());
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java
index c5c47d272034c8f2b494ff7bda90677bda372b50..2fac0eb6e1f9e399bc94b75990f1464f0c11b581 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java
@@ -36,6 +36,7 @@ import android.os.BatteryManager;
import android.os.BatteryStats;
import android.os.BatteryUsageStats;
import android.os.SystemClock;
+import android.provider.Settings;
import android.util.SparseIntArray;
import com.android.internal.os.BatteryStatsHistoryIterator;
@@ -66,6 +67,8 @@ public class BatteryInfoTest {
private static final String STATUS_CHARGING_NO_TIME = "50% - charging";
private static final String STATUS_CHARGING_TIME = "50% - 0 min left until full";
private static final String STATUS_NOT_CHARGING = "Not charging";
+ private static final String STATUS_CHARGING_FUTURE_BYPASS = "50% - Charging optimized";
+ private static final String STATUS_CHARGING_PAUSED = "50% - Charging optimized";
private static final long REMAINING_TIME_NULL = -1;
private static final long REMAINING_TIME = 2;
// Strings are defined in frameworks/base/packages/SettingsLib/res/values/strings.xml
@@ -97,6 +100,10 @@ public class BatteryInfoTest {
mDisChargingBatteryBroadcast = BatteryTestUtils.getDischargingIntent();
mChargingBatteryBroadcast = BatteryTestUtils.getChargingIntent();
+
+ doReturn(false).when(mFeatureFactory.powerUsageFeatureProvider).isExtraDefend();
+ Settings.Global.putInt(mContext.getContentResolver(),
+ BatteryUtils.SETTINGS_GLOBAL_DOCK_DEFENDER_BYPASS, 0);
}
@Test
@@ -231,6 +238,7 @@ public class BatteryInfoTest {
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mChargingBatteryBroadcast,
mBatteryUsageStats, MOCK_ESTIMATE, SystemClock.elapsedRealtime() * 1000,
false /* shortString */);
+
assertThat(info.remainingTimeUs).isEqualTo(TEST_CHARGE_TIME_REMAINING);
assertThat(info.remainingLabel.toString())
.isEqualTo(TEST_CHARGE_TIME_REMAINING_STRINGIFIED);
@@ -249,8 +257,6 @@ public class BatteryInfoTest {
@Test
public void testGetBatteryInfo_chargingWithOverheated_updateChargeLabel() {
- final String expectedString =
- mContext.getString(R.string.battery_tip_limited_temporarily_title);
doReturn(TEST_CHARGE_TIME_REMAINING)
.when(mBatteryUsageStats)
.getChargeTimeRemainingMs();
@@ -262,7 +268,61 @@ public class BatteryInfoTest {
false /* shortString */);
assertThat(info.isOverheated).isTrue();
- assertThat(info.chargeLabel.toString()).contains(expectedString);
+ assertThat(info.chargeLabel.toString()).contains(STATUS_CHARGING_PAUSED);
+ }
+
+ @Test
+ public void testGetBatteryInfo_dockDefenderActive_updateChargeString() {
+ doReturn(TEST_CHARGE_TIME_REMAINING / 1000)
+ .when(mBatteryUsageStats).getChargeTimeRemainingMs();
+ doReturn(true).when(mFeatureFactory.powerUsageFeatureProvider).isExtraDefend();
+ Intent intent = BatteryTestUtils.getCustomBatteryIntent(BatteryManager.BATTERY_PLUGGED_DOCK,
+ 50 /* level */,
+ 100 /* scale */,
+ BatteryManager.BATTERY_STATUS_CHARGING)
+ .putExtra(BatteryManager.EXTRA_HEALTH, BatteryManager.BATTERY_HEALTH_OVERHEAT);
+
+ BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, intent,
+ mBatteryUsageStats, MOCK_ESTIMATE, SystemClock.elapsedRealtime() * 1000,
+ false /* shortString */);
+
+ assertThat(info.chargeLabel.toString()).contains(STATUS_CHARGING_PAUSED);
+ }
+
+ @Test
+ public void testGetBatteryInfo_dockDefenderTemporarilyBypassed_updateChargeLabel() {
+ doReturn(REMAINING_TIME).when(mBatteryUsageStats).getChargeTimeRemainingMs();
+ mChargingBatteryBroadcast
+ .putExtra(BatteryManager.EXTRA_HEALTH, BatteryManager.BATTERY_HEALTH_GOOD);
+ Settings.Global.putInt(mContext.getContentResolver(),
+ BatteryUtils.SETTINGS_GLOBAL_DOCK_DEFENDER_BYPASS, 1);
+
+ BatteryInfo info = BatteryInfo.getBatteryInfo(mContext,
+ BatteryTestUtils.getCustomBatteryIntent(BatteryManager.BATTERY_PLUGGED_DOCK,
+ 50 /* level */,
+ 100 /* scale */,
+ BatteryManager.BATTERY_STATUS_CHARGING),
+ mBatteryUsageStats, MOCK_ESTIMATE, SystemClock.elapsedRealtime() * 1000,
+ false /* shortString */);
+
+ assertThat(info.chargeLabel.toString()).contains(STATUS_CHARGING_TIME);
+ }
+
+ @Test
+ public void testGetBatteryInfo_dockDefenderFutureBypass_updateChargeLabel() {
+ doReturn(false).when(mFeatureFactory.powerUsageFeatureProvider).isExtraDefend();
+ mChargingBatteryBroadcast
+ .putExtra(BatteryManager.EXTRA_HEALTH, BatteryManager.BATTERY_HEALTH_GOOD);
+
+ BatteryInfo info = BatteryInfo.getBatteryInfo(mContext,
+ BatteryTestUtils.getCustomBatteryIntent(BatteryManager.BATTERY_PLUGGED_DOCK,
+ 50 /* level */,
+ 100 /* scale */,
+ BatteryManager.BATTERY_STATUS_CHARGING),
+ mBatteryUsageStats, MOCK_ESTIMATE, SystemClock.elapsedRealtime() * 1000,
+ false /* shortString */);
+
+ assertThat(info.chargeLabel.toString()).contains(STATUS_CHARGING_FUTURE_BYPASS);
}
// Make our battery stats return a sequence of battery events.
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java
index 66a5e7f8bd097e665889a79bf52429015a529027..648685a8d8fcae77122527daab984095908fe010 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java
@@ -132,7 +132,12 @@ public class PowerUsageFeatureProviderImplTest {
}
@Test
- public void testGetResumeChargeIntent_returnNull() {
- assertThat(mPowerFeatureProvider.getResumeChargeIntent()).isNull();
+ public void testGetResumeChargeIntentWithoutDockDefender_returnNull() {
+ assertThat(mPowerFeatureProvider.getResumeChargeIntent(false)).isNull();
+ }
+
+ @Test
+ public void testGetResumeChargeIntentWithDockDefender_returnNull() {
+ assertThat(mPowerFeatureProvider.getResumeChargeIntent(true)).isNull();
}
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragmentTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragmentTest.java
index db1159e1bcf34c3fb6051c350ad55d58b7d15ecf..c5d66a60b458080446902515276d65dda0f3280a 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragmentTest.java
@@ -244,20 +244,4 @@ public class BatteryTipDialogFragmentTest {
assertThat(shadowDialog.getMessage()).isEqualTo(
mContext.getText(R.string.battery_tip_dialog_summary_message));
}
-
- @Test
- public void testOnCreateDialog_defenderTip_fireDialog() {
- mDialogFragment = BatteryTipDialogFragment.newInstance(mDefenderTip, METRICS_KEY);
-
- FragmentController.setupFragment(mDialogFragment, FragmentActivity.class,
- 0 /* containerViewId */, null /* bundle */);
-
- final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
- ShadowAlertDialogCompat shadowDialog = ShadowAlertDialogCompat.shadowOf(dialog);
-
- assertThat(shadowDialog.getTitle()).isEqualTo(
- mContext.getString(R.string.battery_tip_limited_temporarily_title));
- assertThat(shadowDialog.getMessage()).isEqualTo(
- mContext.getString(R.string.battery_tip_limited_temporarily_dialog_msg, "80%"));
- }
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipLoaderTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipLoaderTest.java
index 95280b669bcd39d40184ed43f06946a6208ead24..6d3965e22660a57f8a6282c9d3fa8912893d3a65 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipLoaderTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipLoaderTest.java
@@ -53,6 +53,7 @@ public class BatteryTipLoaderTest {
BatteryTip.TipType.BATTERY_SAVER,
BatteryTip.TipType.LOW_BATTERY,
BatteryTip.TipType.BATTERY_DEFENDER,
+ BatteryTip.TipType.DOCK_DEFENDER,
BatteryTip.TipType.HIGH_DEVICE_USAGE,
BatteryTip.TipType.SMART_BATTERY_MANAGER};
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/detectors/BatteryDefenderDetectorTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/detectors/BatteryDefenderDetectorTest.java
index 90e7ad762a8e976746a3e27ec6ccb9fc8339bedf..f81a4be8d63c9ec2957096641cd73e5ce3035208 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/detectors/BatteryDefenderDetectorTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/detectors/BatteryDefenderDetectorTest.java
@@ -18,10 +18,15 @@ package com.android.settings.fuelgauge.batterytip.detectors;
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.fuelgauge.BatteryInfo;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
+import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
import org.junit.Test;
@@ -36,6 +41,9 @@ public class BatteryDefenderDetectorTest {
@Mock
private BatteryInfo mBatteryInfo;
private BatteryDefenderDetector mBatteryDefenderDetector;
+ private Context mContext;
+
+ private FakeFeatureFactory mFakeFeatureFactory;
@Before
public void setUp() {
@@ -43,20 +51,42 @@ public class BatteryDefenderDetectorTest {
mBatteryInfo.discharging = false;
+ mContext = ApplicationProvider.getApplicationContext();
+
mBatteryDefenderDetector = new BatteryDefenderDetector(
- mBatteryInfo, ApplicationProvider.getApplicationContext());
+ mBatteryInfo, mContext);
+
+ mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
+ }
+
+ @Test
+ public void testDetect_notOverheatedNotExtraDefend_tipInvisible() {
+ mBatteryInfo.isOverheated = false;
+ when(mFakeFeatureFactory.powerUsageFeatureProvider.isExtraDefend()).thenReturn(false);
+
+ assertThat(mBatteryDefenderDetector.detect().isVisible()).isFalse();
+ }
+
+ @Test
+ public void testDetect_notOverheatedIsExtraDefend_tipInvisible() {
+ mBatteryInfo.isOverheated = false;
+ when(mFakeFeatureFactory.powerUsageFeatureProvider.isExtraDefend()).thenReturn(true);
+
+ assertThat(mBatteryDefenderDetector.detect().isVisible()).isFalse();
}
@Test
- public void testDetect_notOverheated_tipInvisible() {
+ public void testDetect_isOverheatedIsExtraDefend_tipInvisible() {
mBatteryInfo.isOverheated = false;
+ when(mFakeFeatureFactory.powerUsageFeatureProvider.isExtraDefend()).thenReturn(true);
assertThat(mBatteryDefenderDetector.detect().isVisible()).isFalse();
}
@Test
- public void testDetect_isOverheated_tipNew() {
+ public void testDetect_isOverheatedNotExtraDefend_tipNew() {
mBatteryInfo.isOverheated = true;
+ when(mFakeFeatureFactory.powerUsageFeatureProvider.isExtraDefend()).thenReturn(false);
assertThat(mBatteryDefenderDetector.detect().getState())
.isEqualTo(BatteryTip.StateType.NEW);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/detectors/DockDefenderDetectorTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/detectors/DockDefenderDetectorTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..9652a00ca188eeada9fa9d360b8c4c22845069dc
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/detectors/DockDefenderDetectorTest.java
@@ -0,0 +1,142 @@
+/*
+ * Copyright (C) 2022 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.fuelgauge.batterytip.detectors;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.refEq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.BatteryManager;
+import android.provider.Settings;
+
+import androidx.test.core.app.ApplicationProvider;
+
+import com.android.settings.fuelgauge.BatteryInfo;
+import com.android.settings.fuelgauge.BatteryUtils;
+import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
+import com.android.settings.fuelgauge.batterytip.tips.DockDefenderTip;
+import com.android.settings.testutils.BatteryTestUtils;
+import com.android.settings.testutils.FakeFeatureFactory;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+
+@RunWith(RobolectricTestRunner.class)
+public class DockDefenderDetectorTest {
+
+ private BatteryInfo mBatteryInfo;
+ private DockDefenderDetector mDockDefenderDetector;
+ private Context mContext;
+ private FakeFeatureFactory mFakeFeatureFactory;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = spy(ApplicationProvider.getApplicationContext());
+ mBatteryInfo = new BatteryInfo();
+ mBatteryInfo.pluggedStatus = BatteryManager.BATTERY_PLUGGED_DOCK;
+ mDockDefenderDetector = new DockDefenderDetector(mBatteryInfo, mContext);
+ Intent intent = BatteryTestUtils.getCustomBatteryIntent(BatteryManager.BATTERY_PLUGGED_DOCK,
+ 50 /* level */, 100 /* scale */, BatteryManager.BATTERY_STATUS_CHARGING);
+ doReturn(intent).when(mContext).registerReceiver(eq(null),
+ refEq(new IntentFilter(Intent.ACTION_BATTERY_CHANGED)));
+
+ Settings.Global.putInt(mContext.getContentResolver(),
+ BatteryUtils.SETTINGS_GLOBAL_DOCK_DEFENDER_BYPASS, 0);
+ mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
+ }
+
+ @Test
+ public void testDetect_dockDefenderTemporarilyBypassed() {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ BatteryUtils.SETTINGS_GLOBAL_DOCK_DEFENDER_BYPASS, 1);
+
+ BatteryTip batteryTip = mDockDefenderDetector.detect();
+
+ assertTrue(batteryTip instanceof DockDefenderTip);
+ assertEquals(((DockDefenderTip) batteryTip).getMode(),
+ BatteryUtils.DockDefenderMode.TEMPORARILY_BYPASSED);
+ }
+
+ @Test
+ public void testDetect_dockDefenderActive() {
+ mBatteryInfo.isOverheated = true;
+ doReturn(true).when(mFakeFeatureFactory.powerUsageFeatureProvider).isExtraDefend();
+
+ BatteryTip batteryTip = mDockDefenderDetector.detect();
+
+ assertTrue(batteryTip instanceof DockDefenderTip);
+ assertEquals(((DockDefenderTip) batteryTip).getMode(),
+ BatteryUtils.DockDefenderMode.ACTIVE);
+ }
+
+ @Test
+ public void testDetect_dockDefenderFutureBypass() {
+ mBatteryInfo.isOverheated = false;
+ doReturn(false).when(mFakeFeatureFactory.powerUsageFeatureProvider).isExtraDefend();
+
+ BatteryTip batteryTip = mDockDefenderDetector.detect();
+
+ assertTrue(batteryTip instanceof DockDefenderTip);
+ assertEquals(((DockDefenderTip) batteryTip).getMode(),
+ BatteryUtils.DockDefenderMode.FUTURE_BYPASS);
+ }
+
+ @Test
+ public void testDetect_overheatedTrue_dockDefenderDisabled() {
+ mBatteryInfo.isOverheated = true;
+ doReturn(false).when(mFakeFeatureFactory.powerUsageFeatureProvider).isExtraDefend();
+
+ BatteryTip batteryTip = mDockDefenderDetector.detect();
+
+ assertTrue(batteryTip instanceof DockDefenderTip);
+ assertEquals(((DockDefenderTip) batteryTip).getMode(),
+ BatteryUtils.DockDefenderMode.DISABLED);
+ }
+
+ @Test
+ public void testDetect_pluggedInAC_dockDefenderDisabled() {
+ mBatteryInfo.pluggedStatus = BatteryManager.BATTERY_PLUGGED_AC;
+
+ BatteryTip batteryTip = mDockDefenderDetector.detect();
+
+ assertTrue(batteryTip instanceof DockDefenderTip);
+ assertEquals(((DockDefenderTip) batteryTip).getMode(),
+ BatteryUtils.DockDefenderMode.DISABLED);
+ }
+
+ @Test
+ public void testDetect_overheatedTrueAndDockDefenderNotTriggered_dockDefenderDisabled() {
+ doReturn(false).when(mFakeFeatureFactory.powerUsageFeatureProvider).isExtraDefend();
+ mBatteryInfo.isOverheated = true;
+
+ BatteryTip batteryTip = mDockDefenderDetector.detect();
+
+ assertTrue(batteryTip instanceof DockDefenderTip);
+ assertEquals(((DockDefenderTip) batteryTip).getMode(),
+ BatteryUtils.DockDefenderMode.DISABLED);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/BatteryDefenderTipTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/BatteryDefenderTipTest.java
index 6bd6b26b78c1fced59832990d0776375b9af089b..8b6033a881100ea886b54cbe4dc8f1b87932096c 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/BatteryDefenderTipTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/BatteryDefenderTipTest.java
@@ -79,19 +79,11 @@ public class BatteryDefenderTipTest {
}
@Test
- public void getSummary_notExtraDefended_showNonExtraDefendedSummary() {
+ public void getSummary_showSummary() {
assertThat(mBatteryDefenderTip.getSummary(mContext))
.isEqualTo(mContext.getString(R.string.battery_tip_limited_temporarily_summary));
}
- @Test
- public void getSummary_extraDefended_showExtraDefendedSummary() {
- BatteryDefenderTip defenderTip = new BatteryDefenderTip(
- BatteryTip.StateType.NEW, /* extraDefended= */ true);
-
- assertThat(defenderTip.getSummary(mContext).toString()).isEqualTo("12%");
- }
-
@Test
public void getIcon_showIcon() {
assertThat(mBatteryDefenderTip.getIconId())
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/DockDefenderTipTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/DockDefenderTipTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..e897a1ca5311596f17bd2b3a9629069233175b66
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/DockDefenderTipTest.java
@@ -0,0 +1,193 @@
+/*
+ * Copyright (C) 2022 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.fuelgauge.batterytip.tips;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+
+import android.app.settings.SettingsEnums;
+import android.content.Context;
+import android.util.Log;
+
+import androidx.preference.Preference;
+import androidx.test.core.app.ApplicationProvider;
+
+import com.android.settings.R;
+import com.android.settings.fuelgauge.BatteryUtils;
+import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.widget.CardPreference;
+import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.shadows.ShadowLog;
+
+@RunWith(RobolectricTestRunner.class)
+public class DockDefenderTipTest {
+ private Context mContext;
+ private DockDefenderTip mDockDefenderTipFutureBypass;
+ private DockDefenderTip mDockDefenderTipActive;
+ private DockDefenderTip mDockDefenderTipTemporarilyBypassed;
+ private DockDefenderTip mDockDefenderTipDisabled;
+ private FakeFeatureFactory mFeatureFactory;
+ private MetricsFeatureProvider mMetricsFeatureProvider;
+
+ @Mock
+ private Preference mPreference;
+ @Mock
+ private CardPreference mCardPreference;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mContext = ApplicationProvider.getApplicationContext();
+ mFeatureFactory = FakeFeatureFactory.setupForTest();
+ mMetricsFeatureProvider = mFeatureFactory.metricsFeatureProvider;
+
+ mDockDefenderTipFutureBypass = new DockDefenderTip(BatteryTip.StateType.NEW,
+ BatteryUtils.DockDefenderMode.FUTURE_BYPASS);
+ mDockDefenderTipActive = new DockDefenderTip(BatteryTip.StateType.NEW,
+ BatteryUtils.DockDefenderMode.ACTIVE);
+ mDockDefenderTipTemporarilyBypassed = new DockDefenderTip(BatteryTip.StateType.NEW,
+ BatteryUtils.DockDefenderMode.TEMPORARILY_BYPASSED);
+ mDockDefenderTipDisabled = new DockDefenderTip(BatteryTip.StateType.INVISIBLE,
+ BatteryUtils.DockDefenderMode.DISABLED);
+
+ doReturn(mContext).when(mPreference).getContext();
+ doReturn(mContext).when(mCardPreference).getContext();
+ }
+
+ @Test
+ public void testGetTitle() {
+ assertThat(mDockDefenderTipFutureBypass.getTitle(mContext).toString()).isEqualTo(
+ mContext.getString(R.string.battery_tip_dock_defender_future_bypass_title));
+ assertThat(mDockDefenderTipActive.getTitle(mContext).toString()).isEqualTo(
+ mContext.getString(R.string.battery_tip_dock_defender_active_title));
+ assertThat(mDockDefenderTipTemporarilyBypassed.getTitle(mContext).toString()).isEqualTo(
+ mContext.getString(R.string.battery_tip_dock_defender_temporarily_bypassed_title));
+ assertThat(mDockDefenderTipDisabled.getTitle(mContext)).isNull();
+ }
+
+ @Test
+ public void testGetSummary() {
+ assertThat(mDockDefenderTipFutureBypass.getSummary(mContext).toString()).isEqualTo(
+ mContext.getString(R.string.battery_tip_dock_defender_future_bypass_summary));
+ assertThat(mDockDefenderTipActive.getSummary(mContext).toString()).isEqualTo(
+ mContext.getString(R.string.battery_tip_dock_defender_active_summary));
+ assertThat(mDockDefenderTipTemporarilyBypassed.getSummary(mContext).toString()).isEqualTo(
+ mContext.getString(
+ R.string.battery_tip_dock_defender_temporarily_bypassed_summary));
+ assertThat(mDockDefenderTipDisabled.getSummary(mContext)).isNull();
+ }
+
+ @Test
+ public void testGetIconId_dockDefenderActive_getProtectedIcon() {
+ assertThat(mDockDefenderTipActive.getIconId()).isEqualTo(
+ R.drawable.ic_battery_status_protected_24dp);
+ }
+
+ @Test
+ public void testGetIconId_dockDefenderNotActive_getUntriggeredIcon() {
+ assertThat(mDockDefenderTipFutureBypass.getIconId()).isEqualTo(
+ R.drawable.ic_battery_dock_defender_untriggered_24dp);
+ assertThat(mDockDefenderTipTemporarilyBypassed.getIconId()).isEqualTo(
+ R.drawable.ic_battery_dock_defender_untriggered_24dp);
+ assertThat(mDockDefenderTipDisabled.getIconId()).isEqualTo(
+ R.drawable.ic_battery_dock_defender_untriggered_24dp);
+ }
+
+ @Test
+ public void testUpdateState() {
+ mDockDefenderTipTemporarilyBypassed.updateState(mDockDefenderTipDisabled);
+
+ assertThat(mDockDefenderTipTemporarilyBypassed.getState()).isEqualTo(
+ BatteryTip.StateType.INVISIBLE);
+ assertThat(mDockDefenderTipTemporarilyBypassed.getMode()).isEqualTo(
+ BatteryUtils.DockDefenderMode.DISABLED);
+ }
+
+ @Test
+ public void testLog() {
+ mDockDefenderTipActive.log(mContext, mMetricsFeatureProvider);
+
+ verify(mMetricsFeatureProvider).action(mContext, SettingsEnums.ACTION_DOCK_DEFENDER_TIP,
+ mDockDefenderTipActive.getState());
+ }
+
+
+ @Test
+ public void testUpdatePreference_dockDefenderTipFutureBypass() {
+ mDockDefenderTipFutureBypass.updatePreference(mCardPreference);
+
+ verify(mCardPreference).setPrimaryButtonVisible(true);
+ verify(mCardPreference).setPrimaryButtonText(
+ mContext.getString(R.string.battery_tip_charge_to_full_button));
+ verifySecondaryButton();
+ }
+
+ @Test
+ public void testUpdatePreference_dockDefenderTipActive() {
+ mDockDefenderTipActive.updatePreference(mCardPreference);
+
+ verify(mCardPreference).setPrimaryButtonVisible(true);
+ verify(mCardPreference).setPrimaryButtonText(
+ mContext.getString(R.string.battery_tip_charge_to_full_button));
+ verifySecondaryButton();
+ }
+
+ @Test
+ public void testUpdatePreference_dockDefenderTipTemporarilyBypassed() {
+ mDockDefenderTipTemporarilyBypassed.updatePreference(mCardPreference);
+
+ verify(mCardPreference).setPrimaryButtonVisible(false);
+ verify(mCardPreference, never()).setPrimaryButtonText(any());
+ verifySecondaryButton();
+ }
+
+ private void verifySecondaryButton() {
+ verify(mCardPreference).setSecondaryButtonText(mContext.getString(R.string.learn_more));
+ verify(mCardPreference).setSecondaryButtonVisible(true);
+ verify(mCardPreference).setSecondaryButtonContentDescription(mContext.getString(
+ R.string.battery_tip_limited_temporarily_sec_button_content_description));
+ }
+
+ @Test
+ public void updatePreference_castFail_logErrorMessage() {
+ mDockDefenderTipActive.updatePreference(mPreference);
+
+ assertThat(getLastErrorLog()).isEqualTo("cast Preference to CardPreference failed");
+ }
+
+ private String getLastErrorLog() {
+ return ShadowLog.getLogsForTag(DockDefenderTip.class.getSimpleName()).stream().filter(
+ log -> log.type == Log.ERROR).reduce((first, second) -> second).orElse(
+ createErrorLog("No Error Log")).msg;
+ }
+
+ private ShadowLog.LogItem createErrorLog(String msg) {
+ return new ShadowLog.LogItem(Log.ERROR, "tag", msg, null);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceControllerTest.java
index 26e0f5074edbd1c05575d19512552fba900090c7..9fbcb1688db5698a11eb61761339e9d284fa0771 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceControllerTest.java
@@ -18,6 +18,8 @@ package com.android.settings.fuelgauge.batteryusage;
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.anyFloat;
+import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.atLeastOnce;
@@ -36,6 +38,7 @@ import android.os.Bundle;
import android.os.LocaleList;
import android.text.format.DateUtils;
import android.view.View;
+import android.view.ViewPropertyAnimator;
import android.widget.LinearLayout;
import androidx.preference.Preference;
@@ -85,6 +88,8 @@ public final class BatteryChartPreferenceControllerTest {
@Mock
private BatteryChartView mHourlyChartView;
@Mock
+ private ViewPropertyAnimator mViewPropertyAnimator;
+ @Mock
private PowerGaugePreference mPowerGaugePreference;
@Mock
private BatteryUtils mBatteryUtils;
@@ -116,6 +121,7 @@ public final class BatteryChartPreferenceControllerTest {
.when(mFeatureFactory.powerUsageFeatureProvider)
.getHideApplicationEntries(mContext);
doReturn(mLayoutParams).when(mDailyChartView).getLayoutParams();
+ setupHourlyChartViewAnimationMock();
mBatteryChartPreferenceController = createController();
mBatteryChartPreferenceController.mPrefContext = mContext;
mBatteryChartPreferenceController.mAppListPrefGroup = mAppListGroup;
@@ -174,11 +180,13 @@ public final class BatteryChartPreferenceControllerTest {
@Test
public void setBatteryChartViewModel_6Hours() {
+ reset(mDailyChartView);
reset(mHourlyChartView);
+ setupHourlyChartViewAnimationMock();
+
mBatteryChartPreferenceController.setBatteryHistoryMap(createBatteryHistoryMap(6));
verify(mDailyChartView, atLeastOnce()).setVisibility(View.GONE);
- verify(mHourlyChartView, atLeastOnce()).setVisibility(View.VISIBLE);
// Ignore fast refresh ui from the data processor callback.
verify(mHourlyChartView, atLeast(0)).setViewModel(null);
verify(mHourlyChartView, atLeastOnce()).setViewModel(new BatteryChartViewModel(
@@ -192,6 +200,10 @@ public final class BatteryChartPreferenceControllerTest {
@Test
public void setBatteryChartViewModel_60Hours() {
+ reset(mDailyChartView);
+ reset(mHourlyChartView);
+ setupHourlyChartViewAnimationMock();
+
BatteryChartViewModel expectedDailyViewModel = new BatteryChartViewModel(
List.of(100, 83, 59, 41),
// "Sat", "Sun", "Mon", "Mon"
@@ -205,16 +217,18 @@ public final class BatteryChartPreferenceControllerTest {
mBatteryChartPreferenceController.setBatteryHistoryMap(createBatteryHistoryMap(60));
verify(mDailyChartView, atLeastOnce()).setVisibility(View.VISIBLE);
- verify(mHourlyChartView, atLeastOnce()).setVisibility(View.GONE);
+ verify(mViewPropertyAnimator, atLeastOnce()).alpha(0f);
verify(mDailyChartView).setViewModel(expectedDailyViewModel);
reset(mDailyChartView);
reset(mHourlyChartView);
+ setupHourlyChartViewAnimationMock();
doReturn(mLayoutParams).when(mDailyChartView).getLayoutParams();
mBatteryChartPreferenceController.mDailyChartIndex = 0;
mBatteryChartPreferenceController.refreshUi();
verify(mDailyChartView).setVisibility(View.VISIBLE);
verify(mHourlyChartView).setVisibility(View.VISIBLE);
+ verify(mViewPropertyAnimator, atLeastOnce()).alpha(1f);
expectedDailyViewModel.setSelectedIndex(0);
verify(mDailyChartView).setViewModel(expectedDailyViewModel);
@@ -234,12 +248,13 @@ public final class BatteryChartPreferenceControllerTest {
reset(mDailyChartView);
reset(mHourlyChartView);
+ setupHourlyChartViewAnimationMock();
doReturn(mLayoutParams).when(mDailyChartView).getLayoutParams();
mBatteryChartPreferenceController.mDailyChartIndex = 1;
mBatteryChartPreferenceController.mHourlyChartIndex = 6;
mBatteryChartPreferenceController.refreshUi();
verify(mDailyChartView).setVisibility(View.VISIBLE);
- verify(mHourlyChartView).setVisibility(View.VISIBLE);
+ verify(mViewPropertyAnimator, atLeastOnce()).alpha(1f);
expectedDailyViewModel.setSelectedIndex(1);
verify(mDailyChartView).setViewModel(expectedDailyViewModel);
BatteryChartViewModel expectedHourlyViewModel = new BatteryChartViewModel(
@@ -264,13 +279,14 @@ public final class BatteryChartPreferenceControllerTest {
reset(mDailyChartView);
reset(mHourlyChartView);
+ setupHourlyChartViewAnimationMock();
doReturn(mLayoutParams).when(mDailyChartView).getLayoutParams();
mBatteryChartPreferenceController.mDailyChartIndex = 2;
mBatteryChartPreferenceController.mHourlyChartIndex =
BatteryChartViewModel.SELECTED_INDEX_ALL;
mBatteryChartPreferenceController.refreshUi();
verify(mDailyChartView).setVisibility(View.VISIBLE);
- verify(mHourlyChartView).setVisibility(View.VISIBLE);
+ verify(mViewPropertyAnimator, atLeastOnce()).alpha(1f);
expectedDailyViewModel.setSelectedIndex(2);
verify(mDailyChartView).setViewModel(expectedDailyViewModel);
verify(mHourlyChartView).setViewModel(new BatteryChartViewModel(
@@ -734,4 +750,11 @@ public final class BatteryChartPreferenceControllerTest {
controller.mPrefContext = mContext;
return controller;
}
+
+ private void setupHourlyChartViewAnimationMock() {
+ doReturn(mViewPropertyAnimator).when(mHourlyChartView).animate();
+ doReturn(mViewPropertyAnimator).when(mViewPropertyAnimator).alpha(anyFloat());
+ doReturn(mViewPropertyAnimator).when(mViewPropertyAnimator).setDuration(anyLong());
+ doReturn(mViewPropertyAnimator).when(mViewPropertyAnimator).setListener(any());
+ }
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/DataProcessorTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/DataProcessorTest.java
index c4832041314056685230a4abbc22f155f462051d..7ac8fdeec580d6c557768475dcff8c54fcce1486 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/DataProcessorTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/DataProcessorTest.java
@@ -329,6 +329,18 @@ public class DataProcessorTest {
public void getDailyTimestamps_notEnoughData_returnEmptyList() {
assertThat(DataProcessor.getDailyTimestamps(new ArrayList<>())).isEmpty();
assertThat(DataProcessor.getDailyTimestamps(List.of(100L))).isEmpty();
+ assertThat(DataProcessor.getDailyTimestamps(List.of(100L, 5400000L))).isEmpty();
+ }
+
+ @Test
+ public void getDailyTimestamps_OneHourDataPerDay_returnEmptyList() {
+ // Timezone GMT+8
+ final List timestamps = List.of(
+ 1641049200000L, // 2022-01-01 23:00:00
+ 1641052800000L, // 2022-01-02 00:00:00
+ 1641056400000L // 2022-01-02 01:00:00
+ );
+ assertThat(DataProcessor.getDailyTimestamps(timestamps)).isEmpty();
}
@Test
@@ -353,14 +365,33 @@ public class DataProcessorTest {
public void getDailyTimestamps_MultipleDaysData_returnExpectedList() {
// Timezone GMT+8
final List timestamps = List.of(
- 1640988000000L, // 2022-01-01 06:00:00
+ 1641045600000L, // 2022-01-01 22:00:00
+ 1641060000000L, // 2022-01-02 02:00:00
+ 1641160800000L, // 2022-01-03 06:00:00
+ 1641232800000L // 2022-01-04 02:00:00
+ );
+
+ final List expectedTimestamps = List.of(
+ 1641045600000L, // 2022-01-01 22:00:00
+ 1641052800000L, // 2022-01-02 00:00:00
+ 1641139200000L, // 2022-01-03 00:00:00
+ 1641225600000L, // 2022-01-04 00:00:00
+ 1641232800000L // 2022-01-04 02:00:00
+ );
+ assertThat(DataProcessor.getDailyTimestamps(timestamps)).isEqualTo(expectedTimestamps);
+ }
+
+ @Test
+ public void getDailyTimestamps_FirstDayOneHourData_returnExpectedList() {
+ // Timezone GMT+8
+ final List timestamps = List.of(
+ 1641049200000L, // 2022-01-01 23:00:00
1641060000000L, // 2022-01-02 02:00:00
1641160800000L, // 2022-01-03 06:00:00
1641254400000L // 2022-01-04 08:00:00
);
final List expectedTimestamps = List.of(
- 1640988000000L, // 2022-01-01 06:00:00
1641052800000L, // 2022-01-02 00:00:00
1641139200000L, // 2022-01-03 00:00:00
1641225600000L, // 2022-01-04 00:00:00
@@ -369,6 +400,44 @@ public class DataProcessorTest {
assertThat(DataProcessor.getDailyTimestamps(timestamps)).isEqualTo(expectedTimestamps);
}
+ @Test
+ public void getDailyTimestamps_LastDayNoData_returnExpectedList() {
+ // Timezone GMT+8
+ final List timestamps = List.of(
+ 1640988000000L, // 2022-01-01 06:00:00
+ 1641060000000L, // 2022-01-02 02:00:00
+ 1641160800000L, // 2022-01-03 06:00:00
+ 1641225600000L // 2022-01-04 00:00:00
+ );
+
+ final List expectedTimestamps = List.of(
+ 1640988000000L, // 2022-01-01 06:00:00
+ 1641052800000L, // 2022-01-02 00:00:00
+ 1641139200000L, // 2022-01-03 00:00:00
+ 1641225600000L // 2022-01-04 00:00:00
+ );
+ assertThat(DataProcessor.getDailyTimestamps(timestamps)).isEqualTo(expectedTimestamps);
+ }
+
+ @Test
+ public void getDailyTimestamps_LastDayOneHourData_returnExpectedList() {
+ // Timezone GMT+8
+ final List timestamps = List.of(
+ 1640988000000L, // 2022-01-01 06:00:00
+ 1641060000000L, // 2022-01-02 02:00:00
+ 1641160800000L, // 2022-01-03 06:00:00
+ 1641229200000L // 2022-01-04 01:00:00
+ );
+
+ final List expectedTimestamps = List.of(
+ 1640988000000L, // 2022-01-01 06:00:00
+ 1641052800000L, // 2022-01-02 00:00:00
+ 1641139200000L, // 2022-01-03 00:00:00
+ 1641225600000L // 2022-01-04 00:00:00
+ );
+ assertThat(DataProcessor.getDailyTimestamps(timestamps)).isEqualTo(expectedTimestamps);
+ }
+
@Test
public void isFromFullCharge_emptyData_returnFalse() {
assertThat(DataProcessor.isFromFullCharge(null)).isFalse();
@@ -579,9 +648,13 @@ public class DataProcessorTest {
ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY, /*consumePercentage=*/ 25.0,
/*foregroundUsageTimeInMs=*/ 50, /*backgroundUsageTimeInMs=*/ 60);
verify(mMetricsFeatureProvider)
- .action(mContext, SettingsEnums.ACTION_BATTERY_USAGE_SHOWN_APP_COUNT, 3);
+ .action(mContext.getApplicationContext(),
+ SettingsEnums.ACTION_BATTERY_USAGE_SHOWN_APP_COUNT,
+ 3);
verify(mMetricsFeatureProvider)
- .action(mContext, SettingsEnums.ACTION_BATTERY_USAGE_HIDDEN_APP_COUNT, 0);
+ .action(mContext.getApplicationContext(),
+ SettingsEnums.ACTION_BATTERY_USAGE_HIDDEN_APP_COUNT,
+ 0);
}
@Test
@@ -674,9 +747,13 @@ public class DataProcessorTest {
assertThat(resultMap.get(0).get(0)).isNotNull();
assertThat(resultMap.get(0).get(DataProcessor.SELECTED_INDEX_ALL)).isNotNull();
verify(mMetricsFeatureProvider)
- .action(mContext, SettingsEnums.ACTION_BATTERY_USAGE_SHOWN_APP_COUNT, 2);
+ .action(mContext.getApplicationContext(),
+ SettingsEnums.ACTION_BATTERY_USAGE_SHOWN_APP_COUNT,
+ 2);
verify(mMetricsFeatureProvider)
- .action(mContext, SettingsEnums.ACTION_BATTERY_USAGE_HIDDEN_APP_COUNT, 0);
+ .action(mContext.getApplicationContext(),
+ SettingsEnums.ACTION_BATTERY_USAGE_HIDDEN_APP_COUNT,
+ 0);
}
@Test
@@ -739,9 +816,13 @@ public class DataProcessorTest {
assertThat(resultMap.get(0).get(0)).isNotNull();
assertThat(resultMap.get(0).get(DataProcessor.SELECTED_INDEX_ALL)).isNotNull();
verify(mMetricsFeatureProvider)
- .action(mContext, SettingsEnums.ACTION_BATTERY_USAGE_SHOWN_APP_COUNT, 1);
+ .action(mContext.getApplicationContext(),
+ SettingsEnums.ACTION_BATTERY_USAGE_SHOWN_APP_COUNT,
+ 1);
verify(mMetricsFeatureProvider)
- .action(mContext, SettingsEnums.ACTION_BATTERY_USAGE_HIDDEN_APP_COUNT, 0);
+ .action(mContext.getApplicationContext(),
+ SettingsEnums.ACTION_BATTERY_USAGE_HIDDEN_APP_COUNT,
+ 0);
}
@Test
@@ -814,9 +895,13 @@ public class DataProcessorTest {
ConvertUtils.CONSUMER_TYPE_UID_BATTERY, /*consumePercentage=*/ 50.0,
/*foregroundUsageTimeInMs=*/ 10, /*backgroundUsageTimeInMs=*/ 20);
verify(mMetricsFeatureProvider)
- .action(mContext, SettingsEnums.ACTION_BATTERY_USAGE_SHOWN_APP_COUNT, 1);
+ .action(mContext.getApplicationContext(),
+ SettingsEnums.ACTION_BATTERY_USAGE_SHOWN_APP_COUNT,
+ 1);
verify(mMetricsFeatureProvider)
- .action(mContext, SettingsEnums.ACTION_BATTERY_USAGE_HIDDEN_APP_COUNT, 1);
+ .action(mContext.getApplicationContext(),
+ SettingsEnums.ACTION_BATTERY_USAGE_HIDDEN_APP_COUNT,
+ 1);
}
@Test
@@ -889,9 +974,13 @@ public class DataProcessorTest {
resultEntry = resultDiffData.getAppDiffEntryList().get(1);
assertThat(resultEntry.mBackgroundUsageTimeInMs).isEqualTo(0);
verify(mMetricsFeatureProvider)
- .action(mContext, SettingsEnums.ACTION_BATTERY_USAGE_SHOWN_APP_COUNT, 2);
+ .action(mContext.getApplicationContext(),
+ SettingsEnums.ACTION_BATTERY_USAGE_SHOWN_APP_COUNT,
+ 2);
verify(mMetricsFeatureProvider)
- .action(mContext, SettingsEnums.ACTION_BATTERY_USAGE_HIDDEN_APP_COUNT, 0);
+ .action(mContext.getApplicationContext(),
+ SettingsEnums.ACTION_BATTERY_USAGE_HIDDEN_APP_COUNT,
+ 0);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/PowerUsageBaseTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/PowerUsageBaseTest.java
index 27009301da9d0006d8b1c86e3b43b3dccbdd62ac..6ed10cd2b9b03e5a6a50d4835b77f1c5264d6a5f 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/PowerUsageBaseTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/PowerUsageBaseTest.java
@@ -15,18 +15,26 @@
*/
package com.android.settings.fuelgauge.batteryusage;
+import static com.android.settings.fuelgauge.batteryusage.PowerUsageBase.KEY_INCLUDE_HISTORY;
+import static com.android.settings.fuelgauge.batteryusage.PowerUsageBase.KEY_REFRESH_TYPE;
+
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.refEq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import android.content.Context;
+import android.os.BatteryUsageStats;
import android.os.Bundle;
import androidx.loader.app.LoaderManager;
+import androidx.loader.content.Loader;
+import com.android.settings.fuelgauge.BatteryBroadcastReceiver;
import com.android.settings.testutils.shadow.ShadowDashboardFragment;
import com.android.settingslib.core.AbstractPreferenceController;
@@ -46,14 +54,15 @@ public class PowerUsageBaseTest {
@Mock
private LoaderManager mLoaderManager;
+ @Mock
+ private Loader mBatteryUsageStatsLoader;
private TestFragment mFragment;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mFragment = spy(new TestFragment());
- doReturn(mLoaderManager).when(mFragment).getLoaderManager();
+ mFragment = spy(new TestFragment(mLoaderManager));
}
@Test
@@ -63,7 +72,62 @@ public class PowerUsageBaseTest {
verify(mLoaderManager, never()).initLoader(anyInt(), any(Bundle.class), any());
}
- public static class TestFragment extends PowerUsageBase {
+ @Test
+ public void restartBatteryInfoLoader() {
+ final Bundle bundle = new Bundle();
+ bundle.putInt(KEY_REFRESH_TYPE, BatteryBroadcastReceiver.BatteryUpdateType.BATTERY_STATUS);
+ bundle.putBoolean(KEY_INCLUDE_HISTORY, false);
+ doReturn(mBatteryUsageStatsLoader).when(mLoaderManager).getLoader(
+ PowerUsageBase.LoaderIndex.BATTERY_USAGE_STATS_LOADER);
+ doReturn(false).when(mBatteryUsageStatsLoader).isReset();
+
+ mFragment.restartBatteryStatsLoader(
+ BatteryBroadcastReceiver.BatteryUpdateType.BATTERY_STATUS);
+
+ verify(mLoaderManager)
+ .restartLoader(eq(PowerUsageBase.LoaderIndex.BATTERY_USAGE_STATS_LOADER),
+ refEq(bundle), any());
+ }
+
+ @Test
+ public void restartBatteryInfoLoader_loaderReset_initLoader() {
+ final Bundle bundle = new Bundle();
+ bundle.putInt(KEY_REFRESH_TYPE, BatteryBroadcastReceiver.BatteryUpdateType.BATTERY_STATUS);
+ bundle.putBoolean(KEY_INCLUDE_HISTORY, false);
+ doReturn(mBatteryUsageStatsLoader).when(mLoaderManager).getLoader(
+ PowerUsageBase.LoaderIndex.BATTERY_USAGE_STATS_LOADER);
+ doReturn(true).when(mBatteryUsageStatsLoader).isReset();
+
+ mFragment.restartBatteryStatsLoader(
+ BatteryBroadcastReceiver.BatteryUpdateType.BATTERY_STATUS);
+
+ verify(mLoaderManager)
+ .initLoader(eq(PowerUsageBase.LoaderIndex.BATTERY_USAGE_STATS_LOADER),
+ refEq(bundle), any());
+ }
+
+ @Test
+ public void restartBatteryInfoLoader_nullLoader_initLoader() {
+ final Bundle bundle = new Bundle();
+ bundle.putInt(KEY_REFRESH_TYPE, BatteryBroadcastReceiver.BatteryUpdateType.BATTERY_STATUS);
+ bundle.putBoolean(KEY_INCLUDE_HISTORY, false);
+ doReturn(null).when(mLoaderManager).getLoader(
+ PowerUsageBase.LoaderIndex.BATTERY_USAGE_STATS_LOADER);
+
+ mFragment.restartBatteryStatsLoader(
+ BatteryBroadcastReceiver.BatteryUpdateType.BATTERY_STATUS);
+
+ verify(mLoaderManager).initLoader(eq(PowerUsageBase.LoaderIndex.BATTERY_USAGE_STATS_LOADER),
+ refEq(bundle), any());
+ }
+
+ private static class TestFragment extends PowerUsageBase {
+
+ private LoaderManager mLoaderManager;
+
+ TestFragment(LoaderManager loaderManager) {
+ mLoaderManager = loaderManager;
+ }
@Override
public int getMetricsCategory() {
@@ -94,5 +158,10 @@ public class PowerUsageBaseTest {
protected List createPreferenceControllers(Context context) {
return null;
}
+
+ @Override
+ protected LoaderManager getLoaderManagerForCurrentFragment() {
+ return mLoaderManager;
+ }
}
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/PowerUsageSummaryTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/PowerUsageSummaryTest.java
index c0494972f355959604433ddab67c1fd95d9c9e56..04bf01937c98da2d7dfb8d906ae6d72ab21e3024 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/PowerUsageSummaryTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/PowerUsageSummaryTest.java
@@ -15,7 +15,6 @@
*/
package com.android.settings.fuelgauge.batteryusage;
-import static com.android.settings.fuelgauge.batteryusage.PowerUsageSummary.BATTERY_INFO_LOADER;
import static com.android.settings.fuelgauge.batteryusage.PowerUsageSummary.KEY_BATTERY_ERROR;
import static com.android.settings.fuelgauge.batteryusage.PowerUsageSummary.KEY_BATTERY_USAGE;
@@ -39,14 +38,17 @@ import android.os.Bundle;
import android.provider.Settings;
import androidx.loader.app.LoaderManager;
+import androidx.loader.content.Loader;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.fuelgauge.BatteryBroadcastReceiver;
+import com.android.settings.fuelgauge.BatteryInfo;
import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController;
+import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.XmlTestUtils;
import com.android.settings.testutils.shadow.ShadowUtils;
@@ -69,8 +71,6 @@ import java.util.List;
// TODO: Improve this test class so that it starts up the real activity and fragment.
@RunWith(RobolectricTestRunner.class)
public class PowerUsageSummaryTest {
-
- private static final long TIME_SINCE_LAST_FULL_CHARGE_MS = 120 * 60 * 1000;
private static Intent sAdditionalBatteryInfoIntent;
@BeforeClass
@@ -83,6 +83,10 @@ public class PowerUsageSummaryTest {
@Mock
private LoaderManager mLoaderManager;
@Mock
+ private Loader mBatteryTipLoader;
+ @Mock
+ private Loader mBatteryInfoLoader;
+ @Mock
private ContentResolver mContentResolver;
@Mock
private BatteryBroadcastReceiver mBatteryBroadcastReceiver;
@@ -105,11 +109,9 @@ public class PowerUsageSummaryTest {
mRealContext = spy(RuntimeEnvironment.application);
mFeatureFactory = FakeFeatureFactory.setupForTest();
- mFragment = spy(new TestFragment(mRealContext));
+ mFragment = spy(new TestFragment(mRealContext, mLoaderManager));
mFragment.initFeatureProvider();
doNothing().when(mFragment).restartBatteryStatsLoader(anyInt());
- doReturn(mock(LoaderManager.class)).when(mFragment).getLoaderManager();
-
when(mFragment.getActivity()).thenReturn(mSettingsActivity);
when(mFeatureFactory.powerUsageFeatureProvider.getAdditionalBatteryInfoIntent())
.thenReturn(sAdditionalBatteryInfoIntent);
@@ -142,7 +144,7 @@ public class PowerUsageSummaryTest {
public void initPreference_hasCorrectSummary() {
mFragment.initPreference();
- verify(mBatteryUsagePreference).setSummary("View usage from last full charge");
+ verify(mBatteryUsagePreference).setSummary("View usage since last full charge");
}
@Test
@@ -155,12 +157,58 @@ public class PowerUsageSummaryTest {
@Test
public void restartBatteryTipLoader() {
//TODO: add policy logic here when BatteryTipPolicy is implemented
- doReturn(mLoaderManager).when(mFragment).getLoaderManager();
+ doReturn(mBatteryTipLoader).when(mLoaderManager).getLoader(
+ PowerUsageBase.LoaderIndex.BATTERY_TIP_LOADER);
+ doReturn(false).when(mBatteryTipLoader).isReset();
+
+ mFragment.restartBatteryTipLoader();
+
+ verify(mLoaderManager).restartLoader(eq(PowerUsageBase.LoaderIndex.BATTERY_TIP_LOADER),
+ eq(Bundle.EMPTY), any());
+ }
+
+ @Test
+ public void restartBatteryTipLoader_nullLoader_initLoader() {
+ doReturn(null).when(mLoaderManager).getLoader(
+ PowerUsageBase.LoaderIndex.BATTERY_TIP_LOADER);
+
+ mFragment.restartBatteryTipLoader();
+
+ verify(mLoaderManager).initLoader(eq(PowerUsageBase.LoaderIndex.BATTERY_TIP_LOADER),
+ eq(Bundle.EMPTY), any());
+ }
+
+ @Test
+ public void restartBatteryTipLoader_loaderReset_initLoader() {
+ doReturn(mBatteryTipLoader).when(mLoaderManager).getLoader(
+ PowerUsageBase.LoaderIndex.BATTERY_TIP_LOADER);
+ doReturn(true).when(mBatteryTipLoader).isReset();
mFragment.restartBatteryTipLoader();
- verify(mLoaderManager)
- .restartLoader(eq(PowerUsageSummary.BATTERY_TIP_LOADER), eq(Bundle.EMPTY), any());
+
+ verify(mLoaderManager).initLoader(eq(PowerUsageBase.LoaderIndex.BATTERY_TIP_LOADER),
+ eq(Bundle.EMPTY), any());
+ }
+
+
+ @Test
+ public void refreshUi_contextNull_doNothing() {
+ doReturn(null).when(mFragment).getContext();
+
+ mFragment.refreshUi(BatteryBroadcastReceiver.BatteryUpdateType.MANUAL);
+
+ verify(mFragment, never()).restartBatteryTipLoader();
+ verify(mFragment, never()).restartBatteryInfoLoader();
+ }
+
+ @Test
+ public void refreshUi_batteryNotPresent_doNothing() {
+ mFragment.setIsBatteryPresent(false);
+ mFragment.refreshUi(BatteryBroadcastReceiver.BatteryUpdateType.MANUAL);
+
+ verify(mFragment, never()).restartBatteryTipLoader();
+ verify(mFragment, never()).restartBatteryInfoLoader();
}
@Test
@@ -168,10 +216,12 @@ public class PowerUsageSummaryTest {
mFragment.mBatteryTipPreferenceController = mock(BatteryTipPreferenceController.class);
when(mFragment.mBatteryTipPreferenceController.needUpdate()).thenReturn(false);
mFragment.updateBatteryTipFlag(new Bundle());
+ doNothing().when(mFragment).restartBatteryInfoLoader();
mFragment.refreshUi(BatteryBroadcastReceiver.BatteryUpdateType.MANUAL);
verify(mFragment, never()).restartBatteryTipLoader();
+ verify(mFragment).restartBatteryInfoLoader();
}
@Test
@@ -179,10 +229,12 @@ public class PowerUsageSummaryTest {
mFragment.mBatteryTipPreferenceController = mock(BatteryTipPreferenceController.class);
when(mFragment.mBatteryTipPreferenceController.needUpdate()).thenReturn(true);
mFragment.updateBatteryTipFlag(new Bundle());
+ doNothing().when(mFragment).restartBatteryInfoLoader();
mFragment.refreshUi(BatteryBroadcastReceiver.BatteryUpdateType.BATTERY_LEVEL);
verify(mFragment, never()).restartBatteryTipLoader();
+ verify(mFragment).restartBatteryInfoLoader();
}
@Test
@@ -190,10 +242,13 @@ public class PowerUsageSummaryTest {
mFragment.mBatteryTipPreferenceController = mock(BatteryTipPreferenceController.class);
when(mFragment.mBatteryTipPreferenceController.needUpdate()).thenReturn(true);
mFragment.updateBatteryTipFlag(new Bundle());
+ doNothing().when(mFragment).restartBatteryInfoLoader();
+ doNothing().when(mFragment).restartBatteryTipLoader();
mFragment.refreshUi(BatteryBroadcastReceiver.BatteryUpdateType.MANUAL);
verify(mFragment).restartBatteryTipLoader();
+ verify(mFragment).restartBatteryInfoLoader();
}
@Test
@@ -217,19 +272,68 @@ public class PowerUsageSummaryTest {
@Test
public void restartBatteryInfoLoader_contextNull_doNothing() {
when(mFragment.getContext()).thenReturn(null);
- when(mFragment.getLoaderManager()).thenReturn(mLoaderManager);
mFragment.restartBatteryInfoLoader();
- verify(mLoaderManager, never()).restartLoader(BATTERY_INFO_LOADER, Bundle.EMPTY,
+ verify(mLoaderManager, never()).restartLoader(
+ PowerUsageBase.LoaderIndex.BATTERY_INFO_LOADER, Bundle.EMPTY,
mFragment.mBatteryInfoLoaderCallbacks);
}
- public static class TestFragment extends PowerUsageSummary {
+ @Test
+ public void restartBatteryInfoLoader_batteryIsNotPresent_doNothing() {
+ mFragment.setIsBatteryPresent(false);
+
+ mFragment.restartBatteryInfoLoader();
+
+ verify(mLoaderManager, never()).restartLoader(
+ PowerUsageBase.LoaderIndex.BATTERY_INFO_LOADER, Bundle.EMPTY,
+ mFragment.mBatteryInfoLoaderCallbacks);
+ }
+
+ @Test
+ public void restartBatteryInfoLoader() {
+ doReturn(mBatteryInfoLoader).when(mLoaderManager).getLoader(
+ PowerUsageBase.LoaderIndex.BATTERY_INFO_LOADER);
+ doReturn(false).when(mBatteryTipLoader).isReset();
+
+ mFragment.restartBatteryInfoLoader();
+
+ verify(mLoaderManager).restartLoader(eq(PowerUsageBase.LoaderIndex.BATTERY_INFO_LOADER),
+ eq(Bundle.EMPTY), any());
+ }
+
+ @Test
+ public void restartBatteryInfoLoader_nullLoader_initLoader() {
+ doReturn(null).when(mLoaderManager).getLoader(
+ PowerUsageBase.LoaderIndex.BATTERY_INFO_LOADER);
+
+ mFragment.restartBatteryInfoLoader();
+
+ verify(mLoaderManager).initLoader(eq(PowerUsageBase.LoaderIndex.BATTERY_INFO_LOADER),
+ eq(Bundle.EMPTY), any());
+ }
+
+ @Test
+ public void restartBatteryInfoLoader_loaderReset_initLoader() {
+ mFragment.setIsBatteryPresent(true);
+ doReturn(mBatteryInfoLoader).when(mLoaderManager).getLoader(
+ PowerUsageBase.LoaderIndex.BATTERY_INFO_LOADER);
+ doReturn(true).when(mBatteryInfoLoader).isReset();
+
+ mFragment.restartBatteryInfoLoader();
+
+ verify(mLoaderManager).initLoader(eq(PowerUsageBase.LoaderIndex.BATTERY_INFO_LOADER),
+ eq(Bundle.EMPTY), any());
+ }
+
+ private static class TestFragment extends PowerUsageSummary {
private Context mContext;
+ private LoaderManager mLoaderManager;
- public TestFragment(Context context) {
+ TestFragment(Context context, LoaderManager loaderManager) {
mContext = context;
+ mLoaderManager = loaderManager;
}
@Override
@@ -242,5 +346,15 @@ public class PowerUsageSummaryTest {
// Override it so we can access this method in test
return super.getContentResolver();
}
+
+ public void setIsBatteryPresent(boolean isBatteryPresent) {
+ mIsBatteryPresent = isBatteryPresent;
+ }
+
+ @Override
+ protected LoaderManager getLoaderManagerForCurrentFragment() {
+ return mLoaderManager;
+ }
}
+
}
diff --git a/tests/robotests/src/com/android/settings/homepage/SettingsHomepageActivityTest.java b/tests/robotests/src/com/android/settings/homepage/SettingsHomepageActivityTest.java
index 4d203a8a6b0b6cd7765f42098b3ebe0e10fc6a18..337b659ddd08b24c8670b4a546c7990e41aaf578 100644
--- a/tests/robotests/src/com/android/settings/homepage/SettingsHomepageActivityTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/SettingsHomepageActivityTest.java
@@ -20,12 +20,17 @@ import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTE
import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.ActivityManager;
+import android.content.Intent;
import android.os.Build;
import android.view.View;
import android.view.Window;
@@ -36,10 +41,12 @@ import androidx.fragment.app.Fragment;
import com.android.settings.R;
import com.android.settings.dashboard.suggestions.SuggestionFeatureProviderImpl;
-import com.android.settings.homepage.contextualcards.slices.BatteryFixSliceTest;
+import com.android.settings.testutils.shadow.ShadowActivityEmbeddingUtils;
+import com.android.settings.testutils.shadow.ShadowPasswordUtils;
import com.android.settings.testutils.shadow.ShadowUserManager;
import com.android.settingslib.core.lifecycle.HideNonSystemOverlayMixin;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -66,6 +73,11 @@ public class SettingsHomepageActivityTest {
MockitoAnnotations.initMocks(this);
}
+ @After
+ public void tearDown() {
+ ShadowPasswordUtils.reset();
+ }
+
@Test
public void launch_shouldHaveAnimationForIaFragment() {
final SettingsHomepageActivity activity = Robolectric.buildActivity(
@@ -147,9 +159,6 @@ public class SettingsHomepageActivityTest {
}
@Test
- @Config(shadows = {
- BatteryFixSliceTest.ShadowBatteryTipLoader.class
- })
public void onStart_isNotDebuggable_shouldHideSystemOverlay() {
ReflectionHelpers.setStaticField(Build.class, "IS_DEBUGGABLE", false);
@@ -166,9 +175,6 @@ public class SettingsHomepageActivityTest {
}
@Test
- @Config(shadows = {
- BatteryFixSliceTest.ShadowBatteryTipLoader.class,
- })
public void onStop_isNotDebuggable_shouldRemoveHideSystemOverlay() {
ReflectionHelpers.setStaticField(Build.class, "IS_DEBUGGABLE", false);
@@ -195,6 +201,48 @@ public class SettingsHomepageActivityTest {
& SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS).isEqualTo(0);
}
+ /** This test is for large screen devices Activity embedding. */
+ @Test
+ @Config(shadows = ShadowActivityEmbeddingUtils.class)
+ public void onNewIntent_flagClearTop_shouldInitRules() {
+ ShadowActivityEmbeddingUtils.setIsEmbeddingActivityEnabled(true);
+ SettingsHomepageActivity activity =
+ spy(Robolectric.buildActivity(SettingsHomepageActivity.class).get());
+ doNothing().when(activity).reloadHighlightMenuKey();
+ TopLevelSettings topLevelSettings = mock(TopLevelSettings.class);
+ doReturn(topLevelSettings).when(activity).getMainFragment();
+
+ activity.onNewIntent(new Intent().setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
+
+ verify(activity).initSplitPairRules();
+ }
+
+ @Test
+ @Config(shadows = {ShadowPasswordUtils.class})
+ public void isCallingAppPermitted_emptyPermission_returnTrue() {
+ SettingsHomepageActivity homepageActivity = spy(new SettingsHomepageActivity());
+
+ assertTrue(homepageActivity.isCallingAppPermitted(""));
+ }
+
+ @Test
+ @Config(shadows = {ShadowPasswordUtils.class})
+ public void isCallingAppPermitted_noGrantedPermission_returnFalse() {
+ SettingsHomepageActivity homepageActivity = spy(new SettingsHomepageActivity());
+
+ assertFalse(homepageActivity.isCallingAppPermitted("android.permission.TEST"));
+ }
+
+ @Test
+ @Config(shadows = {ShadowPasswordUtils.class})
+ public void isCallingAppPermitted_grantedPermission_returnTrue() {
+ SettingsHomepageActivity homepageActivity = spy(new SettingsHomepageActivity());
+ String permission = "android.permission.TEST";
+ ShadowPasswordUtils.addGrantedPermission(permission);
+
+ assertTrue(homepageActivity.isCallingAppPermitted(permission));
+ }
+
@Implements(SuggestionFeatureProviderImpl.class)
public static class ShadowSuggestionFeatureProviderImpl {
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/ContextualCardManagerTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/ContextualCardManagerTest.java
index 69333d7ad9d5a58305e66e7288d880472ea61a47..f18d94f828b7b56624886acfdca1ea8c7ea3a2a1 100644
--- a/tests/robotests/src/com/android/settings/homepage/contextualcards/ContextualCardManagerTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/ContextualCardManagerTest.java
@@ -135,7 +135,7 @@ public class ContextualCardManagerTest {
final List actualCards = mManager.mSavedCards.stream().collect(Collectors.toList());
final List expectedCards = Arrays.asList("test_low_storage", "test_flashlight",
- "test_dark_theme", "test_gesture", "test_battery");
+ "test_dark_theme", "test_gesture", "test_face_enroll");
assertThat(actualCards).containsExactlyElementsIn(expectedCards);
}
@@ -695,9 +695,9 @@ public class ContextualCardManagerTest {
.setViewType(VIEW_TYPE_FULL_WIDTH)
.build());
cards.add(new ContextualCard.Builder()
- .setName("test_battery")
+ .setName("test_face_enroll")
.setCardType(ContextualCard.CardType.SLICE)
- .setSliceUri(CustomSliceRegistry.BATTERY_FIX_SLICE_URI)
+ .setSliceUri(CustomSliceRegistry.FACE_ENROLL_SLICE_URI)
.setViewType(VIEW_TYPE_FULL_WIDTH)
.build());
return cards;
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSliceTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSliceTest.java
deleted file mode 100644
index 78541db4947ec42477886a4c8a29215cbaf57802..0000000000000000000000000000000000000000
--- a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSliceTest.java
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * 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.homepage.contextualcards.slices;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import android.content.Context;
-import android.net.Uri;
-import android.os.BatteryUsageStats;
-
-import androidx.slice.Slice;
-import androidx.slice.SliceMetadata;
-import androidx.slice.SliceProvider;
-import androidx.slice.widget.SliceLiveData;
-
-import com.android.settings.R;
-import com.android.settings.fuelgauge.batterytip.AppInfo;
-import com.android.settings.fuelgauge.batterytip.BatteryTipLoader;
-import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
-import com.android.settings.fuelgauge.batterytip.tips.EarlyWarningTip;
-import com.android.settings.fuelgauge.batterytip.tips.HighUsageTip;
-import com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip;
-import com.android.settings.fuelgauge.batteryusage.BatteryUsageStatsLoader;
-import com.android.settings.slices.SliceBackgroundWorker;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
-import org.robolectric.annotation.Config;
-import org.robolectric.annotation.Implementation;
-import org.robolectric.annotation.Implements;
-import org.robolectric.annotation.Resetter;
-
-import java.util.ArrayList;
-import java.util.List;
-
-@RunWith(RobolectricTestRunner.class)
-@Config(shadows = {
- BatteryFixSliceTest.ShadowBatteryUsageStatsLoader.class,
- BatteryFixSliceTest.ShadowBatteryTipLoader.class
-})
-public class BatteryFixSliceTest {
-
- private Context mContext;
- private BatteryFixSlice mSlice;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- mContext = RuntimeEnvironment.application;
- mSlice = new BatteryFixSlice(mContext);
-
- // Set-up specs for SliceMetadata.
- SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
- }
-
- @After
- public void tearDown() {
- ShadowBatteryTipLoader.reset();
- ShadowSliceBackgroundWorker.reset();
- ShadowEarlyWarningTip.reset();
- }
-
- @Test
- public void refreshBatteryTips_hasImportantTip_shouldReturnTrue() {
- final List tips = new ArrayList<>();
- tips.add(new LowBatteryTip(BatteryTip.StateType.INVISIBLE, false));
- tips.add(new EarlyWarningTip(BatteryTip.StateType.NEW, false));
- ShadowBatteryTipLoader.setBatteryTips(tips);
-
- BatteryFixSlice.refreshBatteryTips(mContext);
-
- assertThat(BatteryFixSlice.isBatteryTipAvailableFromCache(mContext)).isTrue();
- }
-
- @Test
- public void getSlice_unimportantSlice_shouldSkip() {
- final List tips = new ArrayList<>();
- final List appList = new ArrayList<>();
- appList.add(new AppInfo.Builder()
- .setPackageName("com.android.settings")
- .setScreenOnTimeMs(10000L)
- .build());
- tips.add(new LowBatteryTip(BatteryTip.StateType.INVISIBLE, false));
- tips.add(new EarlyWarningTip(BatteryTip.StateType.HANDLED, false));
- tips.add(new HighUsageTip(1000L, appList));
- ShadowBatteryTipLoader.setBatteryTips(tips);
-
- BatteryFixSlice.refreshBatteryTips(mContext);
- final Slice slice = mSlice.getSlice();
-
- assertThat(SliceMetadata.from(mContext, slice).isErrorSlice()).isTrue();
- }
-
- @Test
- @Config(shadows = {
- BatteryFixSliceTest.ShadowEarlyWarningTip.class,
- BatteryFixSliceTest.ShadowSliceBackgroundWorker.class
- })
- public void getSlice_hasImportantTip_shouldTintIcon() {
- final List tips = new ArrayList<>();
- tips.add(new EarlyWarningTip(BatteryTip.StateType.NEW, false));
- // Create fake cache data
- ShadowBatteryTipLoader.setBatteryTips(tips);
- BatteryFixSlice.refreshBatteryTips(mContext);
- // Create fake background worker data
- BatteryFixSlice.BatteryTipWorker batteryTipWorker = mock(
- BatteryFixSlice.BatteryTipWorker.class);
- when(batteryTipWorker.getResults()).thenReturn(tips);
- ShadowSliceBackgroundWorker.setBatteryTipWorkerWorker(batteryTipWorker);
-
- final Slice slice = mSlice.getSlice();
-
- assertThat(ShadowEarlyWarningTip.isIconTintColorIdCalled()).isTrue();
- }
-
- @Implements(BatteryUsageStatsLoader.class)
- public static class ShadowBatteryUsageStatsLoader {
-
- @Implementation
- protected BatteryUsageStats loadInBackground() {
- return null;
- }
- }
-
- @Implements(BatteryTipLoader.class)
- public static class ShadowBatteryTipLoader {
-
- private static List sBatteryTips = new ArrayList<>();
-
- @Resetter
- public static void reset() {
- sBatteryTips = new ArrayList<>();
- }
-
- @Implementation
- protected List loadInBackground() {
- return sBatteryTips;
- }
-
- private static void setBatteryTips(List tips) {
- sBatteryTips = tips;
- }
- }
-
- @Implements(SliceBackgroundWorker.class)
- public static class ShadowSliceBackgroundWorker {
-
- private static BatteryFixSlice.BatteryTipWorker sBatteryTipWorkerWorker;
-
- @Resetter
- public static void reset() {
- sBatteryTipWorkerWorker = null;
- }
-
- @Implementation
- protected static T getInstance(Uri uri) {
- return (T) sBatteryTipWorkerWorker;
- }
-
- public static void setBatteryTipWorkerWorker(BatteryFixSlice.BatteryTipWorker worker) {
- sBatteryTipWorkerWorker = worker;
- }
- }
-
- @Implements(EarlyWarningTip.class)
- public static class ShadowEarlyWarningTip {
-
- private static boolean mIsGetIconTintColorIdCalled;
-
- @Resetter
- public static void reset() {
- mIsGetIconTintColorIdCalled = false;
- }
-
- @Implementation
- protected int getIconTintColorId() {
- mIsGetIconTintColorIdCalled = true;
- return R.color.battery_bad_color_light;
- }
-
- public static boolean isIconTintColorIdCalled() {
- return mIsGetIconTintColorIdCalled;
- }
- }
-}
diff --git a/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorWorkerTest.java b/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorWorkerTest.java
index 2339f4c1d71e586a23c2c71f1349016b8069dabd..cd06bae479dc5d2cf9a61845ef49625e58065ad0 100644
--- a/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorWorkerTest.java
+++ b/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorWorkerTest.java
@@ -38,11 +38,14 @@ import android.media.session.MediaSessionManager;
import android.media.session.PlaybackState;
import android.net.Uri;
+import com.android.settings.bluetooth.Utils;
import com.android.settings.slices.ShadowSliceBackgroundWorker;
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
import com.android.settingslib.bluetooth.BluetoothEventManager;
+import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
+import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
import com.android.settingslib.media.LocalMediaManager;
import org.junit.Before;
@@ -69,13 +72,17 @@ public class MediaOutputIndicatorWorkerTest {
@Mock
private BluetoothEventManager mBluetoothEventManager;
@Mock
- private LocalBluetoothManager mLocalBluetoothManager;
+ private LocalBluetoothManager mLocalBtManager;
+ @Mock
+ private LocalBluetoothProfileManager mLocalBluetoothProfileManager;
@Mock
private MediaSessionManager mMediaSessionManager;
@Mock
private MediaController mMediaController;
@Mock
private LocalMediaManager mLocalMediaManager;
+ @Mock
+ private LocalBluetoothLeBroadcast mLeAudioBroadcastProfile;
private Context mContext;
private MediaOutputIndicatorWorker mMediaOutputIndicatorWorker;
@@ -84,14 +91,18 @@ public class MediaOutputIndicatorWorkerTest {
private List mMediaControllers = new ArrayList<>();
private PlaybackState mPlaybackState;
private MediaController.PlaybackInfo mPlaybackInfo;
+ private LocalBluetoothManager mLocalBluetoothManager;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mShadowApplication = ShadowApplication.getInstance();
mContext = spy(RuntimeEnvironment.application);
- ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBluetoothManager;
+ ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBtManager;
+ mLocalBluetoothManager = Utils.getLocalBtManager(mContext);
when(mLocalBluetoothManager.getEventManager()).thenReturn(mBluetoothEventManager);
+ when(mLocalBluetoothManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager);
+ when(mLocalBluetoothProfileManager.getLeAudioBroadcastProfile()).thenReturn(null);
mMediaOutputIndicatorWorker = new MediaOutputIndicatorWorker(mContext, URI);
doReturn(mMediaSessionManager).when(mContext).getSystemService(MediaSessionManager.class);
mMediaControllers.add(mMediaController);
@@ -284,4 +295,22 @@ public class MediaOutputIndicatorWorkerTest {
assertThat(mMediaOutputIndicatorWorker.getActiveLocalMediaController()).isNull();
}
+
+ @Test
+ public void isBroadcastSupported_leAudioBroadcastProfileIsNull_returnFalse() {
+ mMediaOutputIndicatorWorker.mLocalMediaManager = mLocalMediaManager;
+ mMediaOutputIndicatorWorker.onSlicePinned();
+
+ assertThat(mMediaOutputIndicatorWorker.isBroadcastSupported()).isFalse();
+ }
+
+ @Test
+ public void isBroadcastSupported_leAudioBroadcastProfileNotNull_returnTrue() {
+ mMediaOutputIndicatorWorker.mLocalMediaManager = mLocalMediaManager;
+ mMediaOutputIndicatorWorker.onSlicePinned();
+ when(mLocalBluetoothProfileManager.getLeAudioBroadcastProfile())
+ .thenReturn(mLeAudioBroadcastProfile);
+
+ assertThat(mMediaOutputIndicatorWorker.isBroadcastSupported()).isTrue();
+ }
}
diff --git a/tests/robotests/src/com/android/settings/media/MediaOutputUtilsTest.java b/tests/robotests/src/com/android/settings/media/MediaOutputUtilsTest.java
index dea6a2c81ab8af8ca49e678cfdf3af00cfe74bc0..5fa7fdd0c640688e1de7fd7870872f7eae4712f8 100644
--- a/tests/robotests/src/com/android/settings/media/MediaOutputUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/media/MediaOutputUtilsTest.java
@@ -66,7 +66,18 @@ public class MediaOutputUtilsTest {
@Test
public void getActiveLocalMediaController_localMediaPlaying_returnController() {
- initPlayback();
+ initPlayback(PlaybackState.STATE_PLAYING);
+
+ when(mMediaController.getPlaybackInfo()).thenReturn(mPlaybackInfo);
+ when(mMediaController.getPlaybackState()).thenReturn(mPlaybackState);
+
+ assertThat(MediaOutputUtils.getActiveLocalMediaController(mMediaSessionManager)).isEqualTo(
+ mMediaController);
+ }
+
+ @Test
+ public void getActiveLocalMediaController_localMediaPause_returnController() {
+ initPlayback(PlaybackState.STATE_PAUSED);
when(mMediaController.getPlaybackInfo()).thenReturn(mPlaybackInfo);
when(mMediaController.getPlaybackState()).thenReturn(mPlaybackState);
@@ -113,6 +124,44 @@ public class MediaOutputUtilsTest {
assertThat(MediaOutputUtils.getActiveLocalMediaController(mMediaSessionManager)).isNull();
}
+ @Test
+ public void getActiveLocalMediaController_localMediaNone_returnNull() {
+ mPlaybackInfo = new MediaController.PlaybackInfo(
+ MediaController.PlaybackInfo.PLAYBACK_TYPE_LOCAL,
+ VolumeProvider.VOLUME_CONTROL_ABSOLUTE,
+ 100,
+ 10,
+ new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_MEDIA).build(),
+ null);
+ mPlaybackState = new PlaybackState.Builder()
+ .setState(PlaybackState.STATE_NONE, 0, 1)
+ .build();
+
+ when(mMediaController.getPlaybackInfo()).thenReturn(mPlaybackInfo);
+ when(mMediaController.getPlaybackState()).thenReturn(mPlaybackState);
+
+ assertThat(MediaOutputUtils.getActiveLocalMediaController(mMediaSessionManager)).isNull();
+ }
+
+ @Test
+ public void getActiveLocalMediaController_localMediaError_returnNull() {
+ mPlaybackInfo = new MediaController.PlaybackInfo(
+ MediaController.PlaybackInfo.PLAYBACK_TYPE_LOCAL,
+ VolumeProvider.VOLUME_CONTROL_ABSOLUTE,
+ 100,
+ 10,
+ new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_MEDIA).build(),
+ null);
+ mPlaybackState = new PlaybackState.Builder()
+ .setState(PlaybackState.STATE_ERROR, 0, 1)
+ .build();
+
+ when(mMediaController.getPlaybackInfo()).thenReturn(mPlaybackInfo);
+ when(mMediaController.getPlaybackState()).thenReturn(mPlaybackState);
+
+ assertThat(MediaOutputUtils.getActiveLocalMediaController(mMediaSessionManager)).isNull();
+ }
+
@Test
public void getActiveLocalMediaController_bothHaveRemoteMediaAndLocalMedia_returnNull() {
mMediaControllers.clear();
@@ -130,7 +179,7 @@ public class MediaOutputUtilsTest {
mMediaControllers.add(remoteMediaController);
mMediaControllers.add(mMediaController);
- initPlayback();
+ initPlayback(PlaybackState.STATE_PLAYING);
when(mMediaController.getPlaybackInfo()).thenReturn(mPlaybackInfo);
when(mMediaController.getPlaybackState()).thenReturn(mPlaybackState);
@@ -155,7 +204,7 @@ public class MediaOutputUtilsTest {
final MediaController remoteMediaController = mock(MediaController.class);
mMediaControllers.add(remoteMediaController);
- initPlayback();
+ initPlayback(PlaybackState.STATE_PLAYING);
when(mMediaController.getPlaybackInfo()).thenReturn(mPlaybackInfo);
when(mMediaController.getPlaybackState()).thenReturn(mPlaybackState);
@@ -165,7 +214,7 @@ public class MediaOutputUtilsTest {
assertThat(MediaOutputUtils.getActiveLocalMediaController(mMediaSessionManager)).isNull();
}
- private void initPlayback() {
+ private void initPlayback(int playbackState) {
mPlaybackInfo = new MediaController.PlaybackInfo(
MediaController.PlaybackInfo.PLAYBACK_TYPE_LOCAL,
VolumeProvider.VOLUME_CONTROL_ABSOLUTE,
@@ -174,7 +223,7 @@ public class MediaOutputUtilsTest {
new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_MEDIA).build(),
null);
mPlaybackState = new PlaybackState.Builder()
- .setState(PlaybackState.STATE_PLAYING, 0, 1)
+ .setState(playbackState, 0, 1)
.build();
}
}
diff --git a/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java b/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java
index 5122def9843b23a47a1edd4b2692c848625188e5..35891843c1bb94f37a8e942f93bd82a4f7467416 100644
--- a/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java
@@ -17,9 +17,11 @@ package com.android.settings.network;
import static com.android.settings.network.NetworkProviderSettings.MENU_ID_DISCONNECT;
import static com.android.settings.network.NetworkProviderSettings.MENU_ID_FORGET;
+import static com.android.settings.network.NetworkProviderSettings.MENU_ID_MODIFY;
import static com.android.settings.network.NetworkProviderSettings.MENU_ID_SHARE;
import static com.android.settings.wifi.WifiConfigUiBase2.MODE_CONNECT;
import static com.android.settings.wifi.WifiConfigUiBase2.MODE_MODIFY;
+import static com.android.wifitrackerlib.WifiEntry.CONNECTED_STATE_DISCONNECTED;
import static com.google.common.truth.Truth.assertThat;
@@ -729,6 +731,28 @@ public class NetworkProviderSettingsTest {
verify(mContextMenu, never()).add(anyInt(), eq(MENU_ID_FORGET), anyInt(), anyInt());
}
+ @Test
+ public void addModifyMenuIfSuitable_isAdmin_addMenu() {
+ mNetworkProviderSettings.mIsAdmin = true;
+ when(mWifiEntry.isSaved()).thenReturn(true);
+ when(mWifiEntry.getConnectedState()).thenReturn(CONNECTED_STATE_DISCONNECTED);
+
+ mNetworkProviderSettings.addModifyMenuIfSuitable(mContextMenu, mWifiEntry);
+
+ verify(mContextMenu).add(anyInt(), eq(MENU_ID_MODIFY), anyInt(), anyInt());
+ }
+
+ @Test
+ public void addModifyMenuIfSuitable_isNotAdmin_notAddMenu() {
+ mNetworkProviderSettings.mIsAdmin = false;
+ when(mWifiEntry.isSaved()).thenReturn(true);
+ when(mWifiEntry.getConnectedState()).thenReturn(CONNECTED_STATE_DISCONNECTED);
+
+ mNetworkProviderSettings.addModifyMenuIfSuitable(mContextMenu, mWifiEntry);
+
+ verify(mContextMenu, never()).add(anyInt(), eq(MENU_ID_MODIFY), anyInt(), anyInt());
+ }
+
@Test
public void getNonIndexableKeys_allowedChangeWifiState_keyNotReturned() {
when(mWifiRestriction.isChangeWifiStateAllowed(mContext)).thenReturn(true);
diff --git a/tests/robotests/src/com/android/settings/notification/MediaVolumePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/MediaVolumePreferenceControllerTest.java
index 56e83bb90ae632cbdbbd6356e88e592a56d70b8b..2d023d7142f918cb5ab99e43b51350c5948b39d8 100644
--- a/tests/robotests/src/com/android/settings/notification/MediaVolumePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/MediaVolumePreferenceControllerTest.java
@@ -113,13 +113,23 @@ public class MediaVolumePreferenceControllerTest {
@Test
public void isSupportEndItem_withBleDevice_returnsTrue() {
+ doReturn(true).when(sMediaOutputIndicatorWorker).isBroadcastSupported();
doReturn(mDevice1).when(sMediaOutputIndicatorWorker).getCurrentConnectedMediaDevice();
assertThat(mController.isSupportEndItem()).isTrue();
}
+ @Test
+ public void isSupportEndItem_notSupportedBroadcast_returnsFalse() {
+ doReturn(false).when(sMediaOutputIndicatorWorker).isBroadcastSupported();
+ doReturn(mDevice1).when(sMediaOutputIndicatorWorker).getCurrentConnectedMediaDevice();
+
+ assertThat(mController.isSupportEndItem()).isFalse();
+ }
+
@Test
public void isSupportEndItem_withNonBleDevice_returnsFalse() {
+ doReturn(true).when(sMediaOutputIndicatorWorker).isBroadcastSupported();
doReturn(mDevice2).when(sMediaOutputIndicatorWorker).getCurrentConnectedMediaDevice();
assertThat(mController.isSupportEndItem()).isFalse();
@@ -127,6 +137,7 @@ public class MediaVolumePreferenceControllerTest {
@Test
public void getSliceEndItem_NotSupportEndItem_getsNullSliceAction() {
+ doReturn(true).when(sMediaOutputIndicatorWorker).isBroadcastSupported();
doReturn(mDevice2).when(sMediaOutputIndicatorWorker).getCurrentConnectedMediaDevice();
final SliceAction sliceAction = mController.getSliceEndItem(mContext);
@@ -136,6 +147,7 @@ public class MediaVolumePreferenceControllerTest {
@Test
public void getSliceEndItem_deviceIsBroadcasting_getsBroadcastIntent() {
+ doReturn(true).when(sMediaOutputIndicatorWorker).isBroadcastSupported();
doReturn(mDevice1).when(sMediaOutputIndicatorWorker).getCurrentConnectedMediaDevice();
doReturn(true).when(sMediaOutputIndicatorWorker).isDeviceBroadcasting();
doReturn(mMediaController).when(sMediaOutputIndicatorWorker)
@@ -155,6 +167,7 @@ public class MediaVolumePreferenceControllerTest {
final CachedBluetoothDevice cachedDevice = mock(CachedBluetoothDevice.class);
when(((BluetoothMediaDevice) device).getCachedDevice()).thenReturn(cachedDevice);
when(device.isBLEDevice()).thenReturn(true);
+ doReturn(true).when(sMediaOutputIndicatorWorker).isBroadcastSupported();
doReturn(device).when(sMediaOutputIndicatorWorker).getCurrentConnectedMediaDevice();
doReturn(false).when(sMediaOutputIndicatorWorker).isDeviceBroadcasting();
doReturn(mMediaController).when(sMediaOutputIndicatorWorker)
diff --git a/tests/robotests/src/com/android/settings/notification/NotificationAssistantPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/NotificationAssistantPreferenceControllerTest.java
index b594667381567d3915044631a8df083ed32709c1..1dac399dd70205a9d10074ad83ed835f6401dc8f 100644
--- a/tests/robotests/src/com/android/settings/notification/NotificationAssistantPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/NotificationAssistantPreferenceControllerTest.java
@@ -226,4 +226,14 @@ public class NotificationAssistantPreferenceControllerTest {
.setNASMigrationDoneAndResetDefault(eq(10), anyBoolean());
}
+ @Test
+ public void testNASUnavailable_settingDisabled() throws Exception {
+ when(mBackend.getDefaultNotificationAssistant()).thenReturn(null);
+ mPreferenceController.getDefaultNASIntent();
+ mPreferenceController.updateState(mPreference);
+
+ verify(mPreference, times(1)).setSwitchEnabled(eq(false));
+ assertFalse(mPreference.isEnabled());
+ }
+
}
diff --git a/tests/robotests/src/com/android/settings/notification/NotificationVolumePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/NotificationVolumePreferenceControllerTest.java
index fe4744fecab442758ee328cfa0b1f30e931929a3..7e7ad10d8c14e302f2ef71cf94ecf7a294f97c20 100644
--- a/tests/robotests/src/com/android/settings/notification/NotificationVolumePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/NotificationVolumePreferenceControllerTest.java
@@ -18,14 +18,26 @@ package com.android.settings.notification;
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
+import android.content.res.Resources;
import android.media.AudioManager;
import android.os.Vibrator;
+import android.provider.DeviceConfig;
+import android.service.notification.NotificationListenerService;
import android.telephony.TelephonyManager;
+import androidx.preference.PreferenceManager;
+import androidx.preference.PreferenceScreen;
+import androidx.test.core.app.ApplicationProvider;
+
+import com.android.internal.config.sysui.SystemUiDeviceConfigFlags;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.testutils.shadow.ShadowDeviceConfig;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -33,11 +45,12 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
+import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
@RunWith(RobolectricTestRunner.class)
+@Config(shadows = {ShadowDeviceConfig.class})
public class NotificationVolumePreferenceControllerTest {
-
@Mock
private AudioHelper mHelper;
@Mock
@@ -46,6 +59,13 @@ public class NotificationVolumePreferenceControllerTest {
private AudioManager mAudioManager;
@Mock
private Vibrator mVibrator;
+ @Mock
+ private Resources mResources;
+ @Mock
+ private PreferenceManager mPreferenceManager;
+
+ private static final String READ_DEVICE_CONFIG_PERMISSION =
+ "android.permission.READ_DEVICE_CONFIG";
private Context mContext;
private NotificationVolumePreferenceController mController;
@@ -57,6 +77,8 @@ public class NotificationVolumePreferenceControllerTest {
when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
when(mContext.getSystemService(Context.AUDIO_SERVICE)).thenReturn(mAudioManager);
when(mContext.getSystemService(Context.VIBRATOR_SERVICE)).thenReturn(mVibrator);
+ when(mContext.getResources()).thenReturn(mResources);
+
mController = new NotificationVolumePreferenceController(mContext);
mController.setAudioHelper(mHelper);
}
@@ -76,15 +98,54 @@ public class NotificationVolumePreferenceControllerTest {
}
@Test
- public void isAvailable_voiceCapable_shouldReturnFalse() {
+ public void isAvailable_voiceCapable_aliasedWithRing_shouldReturnFalse() {
+ when(mResources.getBoolean(
+ com.android.settings.R.bool.config_show_notification_volume)).thenReturn(true);
+
+ DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
+ SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, "false", false);
+
+ NotificationVolumePreferenceController controller =
+ new NotificationVolumePreferenceController(mContext);
+ when(mHelper.isSingleVolume()).thenReturn(false);
+ when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
+
+ assertThat(controller.isAvailable()).isFalse();
+ }
+
+ /**
+ * With the introduction of ring-notification volume separation, voice-capable devices could now
+ * display the notification volume slider.
+ */
+ @Test
+ public void isAvailable_voiceCapable_separatedFromRing_shouldReturnTrue() {
+ when(mResources.getBoolean(
+ com.android.settings.R.bool.config_show_notification_volume)).thenReturn(true);
+
+ DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
+ SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, "true", false);
+
+ NotificationVolumePreferenceController controller =
+ new NotificationVolumePreferenceController(mContext);
+
when(mHelper.isSingleVolume()).thenReturn(false);
when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
+ assertThat(controller.isAvailable()).isTrue();
+ }
+
+ @Test
+ public void isAvailable_notShowNotificationVolume_shouldReturnFalse() {
+ when(mResources.getBoolean(
+ com.android.settings.R.bool.config_show_notification_volume)).thenReturn(false);
+
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void isAvailable_notSingleVolume_notVoiceCapable_shouldReturnTrue() {
+ when(mResources.getBoolean(
+ com.android.settings.R.bool.config_show_notification_volume)).thenReturn(true);
when(mHelper.isSingleVolume()).thenReturn(false);
when(mTelephonyManager.isVoiceCapable()).thenReturn(false);
@@ -107,4 +168,90 @@ public class NotificationVolumePreferenceControllerTest {
public void isPublicSlice_returnTrue() {
assertThat(mController.isPublicSlice()).isTrue();
}
+
+ @Test
+ public void setHintsRing_DoesNotMatch() {
+ assertThat(mController.hintsMatch(
+ NotificationListenerService.HINT_HOST_DISABLE_CALL_EFFECTS)).isFalse();
+ }
+
+ @Test
+ public void setHintsAll_Matches() {
+ assertThat(mController.hintsMatch(NotificationListenerService.HINT_HOST_DISABLE_EFFECTS))
+ .isTrue();
+ }
+
+ @Test
+ public void setHintNotification_Matches() {
+ assertThat(mController
+ .hintsMatch(NotificationListenerService.HINT_HOST_DISABLE_NOTIFICATION_EFFECTS))
+ .isTrue();
+ }
+
+ @Test
+ public void enableSeparateNotificationConfig_controllerBecomesAvailable() {
+ PreferenceScreen screen = spy(new PreferenceScreen(mContext, null));
+ VolumeSeekBarPreference volumeSeekBarPreference = mock(VolumeSeekBarPreference.class);
+ when(screen.getPreferenceManager()).thenReturn(mPreferenceManager);
+ when(screen.getContext()).thenReturn(mContext);
+ when(mResources.getBoolean(
+ com.android.settings.R.bool.config_show_notification_volume)).thenReturn(true);
+ // block the alternative condition to enable controller
+ when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
+
+ DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
+ SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, "false", false);
+
+ NotificationVolumePreferenceController controller =
+ new NotificationVolumePreferenceController(mContext);
+ when(screen.findPreference(controller.getPreferenceKey()))
+ .thenReturn(volumeSeekBarPreference);
+
+ // allow the controller to subscribe
+ Shadows.shadowOf((android.app.Application) ApplicationProvider.getApplicationContext())
+ .grantPermissions(READ_DEVICE_CONFIG_PERMISSION);
+ controller.onResume();
+ controller.displayPreference(screen);
+
+ DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
+ SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, Boolean.toString(true),
+ false);
+
+ assertThat(controller.getAvailabilityStatus()
+ == BasePreferenceController.AVAILABLE).isTrue();
+ }
+
+ @Test
+ public void disableSeparateNotificationConfig_controllerBecomesUnavailable() {
+ PreferenceScreen screen = spy(new PreferenceScreen(mContext, null));
+ VolumeSeekBarPreference volumeSeekBarPreference = mock(VolumeSeekBarPreference.class);
+ when(screen.getPreferenceManager()).thenReturn(mPreferenceManager);
+ when(screen.getContext()).thenReturn(mContext);
+ when(mResources.getBoolean(
+ com.android.settings.R.bool.config_show_notification_volume)).thenReturn(true);
+
+ // block the alternative condition to enable controller
+ when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
+
+ DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
+ SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, "true", false);
+
+ NotificationVolumePreferenceController controller =
+ new NotificationVolumePreferenceController(mContext);
+
+ when(screen.findPreference(controller.getPreferenceKey()))
+ .thenReturn(volumeSeekBarPreference);
+
+ Shadows.shadowOf((android.app.Application) ApplicationProvider.getApplicationContext())
+ .grantPermissions(READ_DEVICE_CONFIG_PERMISSION);
+ controller.onResume();
+ controller.displayPreference(screen);
+
+ DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
+ SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, "false", false);
+
+ assertThat(controller.getAvailabilityStatus()
+ == BasePreferenceController.UNSUPPORTED_ON_DEVICE).isTrue();
+ }
+
}
diff --git a/tests/robotests/src/com/android/settings/notification/RedactionInterstitialTest.java b/tests/robotests/src/com/android/settings/notification/RedactionInterstitialTest.java
index 5c6da4952358b4fb3b98718382f0e6078a03889a..9d475b84524e2536317f4d5c94f341864bc319fa 100644
--- a/tests/robotests/src/com/android/settings/notification/RedactionInterstitialTest.java
+++ b/tests/robotests/src/com/android/settings/notification/RedactionInterstitialTest.java
@@ -21,6 +21,7 @@ import android.widget.RadioButton;
import com.android.settings.R;
import com.android.settings.RestrictedRadioButton;
import com.android.settings.notification.RedactionInterstitial.RedactionInterstitialFragment;
+import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtilsInternal;
import com.android.settings.testutils.shadow.ShadowUtils;
@@ -38,6 +39,7 @@ import org.robolectric.shadows.ShadowUserManager;
@Config(shadows = {
ShadowUtils.class,
ShadowRestrictedLockUtilsInternal.class,
+ SettingsShadowResources.class,
})
public class RedactionInterstitialTest {
private RedactionInterstitial mActivity;
@@ -134,6 +136,28 @@ public class RedactionInterstitialTest {
assertSelectedButton(R.id.redact_sensitive);
}
+ @Test
+ public void defaultShowSensitiveContent_configDeny() {
+ final ContentResolver resolver = RuntimeEnvironment.application.getContentResolver();
+ Settings.Secure.putIntForUser(resolver,
+ LOCK_SCREEN_SHOW_NOTIFICATIONS, 1, UserHandle.myUserId());
+ setupConfig(false);
+ setupActivity();
+
+ assertSelectedButton(R.id.redact_sensitive);
+ }
+
+ @Test
+ public void defaultShowSensitiveContent_configAllow() {
+ final ContentResolver resolver = RuntimeEnvironment.application.getContentResolver();
+ Settings.Secure.putIntForUser(resolver,
+ LOCK_SCREEN_SHOW_NOTIFICATIONS, 1, UserHandle.myUserId());
+ setupConfig(true);
+ setupActivity();
+
+ assertSelectedButton(R.id.show_all);
+ }
+
private void setupActivity() {
mActivity = buildActivity(RedactionInterstitial.class, new Intent()).setup().get();
mFragment = (RedactionInterstitialFragment)
@@ -142,6 +166,11 @@ public class RedactionInterstitialTest {
assertThat(mFragment).isNotNull();
}
+ private void setupConfig(boolean allowSensitiveContent) {
+ SettingsShadowResources.overrideResource(
+ R.bool.default_allow_sensitive_lockscreen_content, allowSensitiveContent);
+ }
+
private void setupSettings(int show, int showUnredacted) {
final ContentResolver resolver = RuntimeEnvironment.application.getContentResolver();
Settings.Secure.putIntForUser(resolver,
diff --git a/tests/robotests/src/com/android/settings/notification/RingVolumePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/RingVolumePreferenceControllerTest.java
index 5e484a3bfd560b39d84039907417ce4620ab76c3..1ad26c7154685e00fa9f6b50212a2429dc59fc04 100644
--- a/tests/robotests/src/com/android/settings/notification/RingVolumePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/RingVolumePreferenceControllerTest.java
@@ -18,15 +18,23 @@ package com.android.settings.notification;
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.app.NotificationManager;
import android.content.ComponentName;
import android.content.Context;
+import android.content.res.Resources;
import android.media.AudioManager;
import android.os.Vibrator;
+import android.provider.DeviceConfig;
+import android.service.notification.NotificationListenerService;
import android.telephony.TelephonyManager;
+import com.android.internal.config.sysui.SystemUiDeviceConfigFlags;
+import com.android.settings.R;
+import com.android.settings.testutils.shadow.ShadowDeviceConfig;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -34,9 +42,11 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
@RunWith(RobolectricTestRunner.class)
+@Config(shadows = {ShadowDeviceConfig.class})
public class RingVolumePreferenceControllerTest {
@Mock
@@ -51,8 +61,13 @@ public class RingVolumePreferenceControllerTest {
private NotificationManager mNotificationManager;
@Mock
private ComponentName mSuppressor;
+ @Mock
+ private Resources mResources;
+ @Mock
+ private VolumeSeekBarPreference mPreference;
private Context mContext;
+
private RingVolumePreferenceController mController;
@Before
@@ -63,8 +78,9 @@ public class RingVolumePreferenceControllerTest {
shadowContext.setSystemService(Context.AUDIO_SERVICE, mAudioManager);
shadowContext.setSystemService(Context.VIBRATOR_SERVICE, mVibrator);
shadowContext.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
- mContext = RuntimeEnvironment.application;
+ mContext = spy(RuntimeEnvironment.application);
when(mNotificationManager.getEffectsSuppressor()).thenReturn(mSuppressor);
+ when(mContext.getResources()).thenReturn(mResources);
mController = new RingVolumePreferenceController(mContext);
mController.setAudioHelper(mHelper);
}
@@ -109,4 +125,94 @@ public class RingVolumePreferenceControllerTest {
public void isPublicSlice_returnTrue() {
assertThat(mController.isPublicSlice()).isTrue();
}
+
+ // todo: verify that the title change is displayed, by examining the underlying preference
+ @Test
+ public void ringNotificationStreamsNotAliased_sliderTitleSetToRingOnly() {
+
+ DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
+ SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, "true", false);
+
+ final RingVolumePreferenceController controller =
+ new RingVolumePreferenceController(mContext);
+
+ int expectedTitleId = R.string.separate_ring_volume_option_title;
+
+ assertThat(controller.mTitleId).isEqualTo(expectedTitleId);
+ }
+
+ @Test
+ public void ringNotificationStreamsAliased_sliderTitleIncludesBothRingNotification() {
+
+ DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
+ SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, "false", false);
+
+ final RingVolumePreferenceController control = new RingVolumePreferenceController(mContext);
+
+ int expectedTitleId = R.string.ring_volume_option_title;
+
+ assertThat(control.mTitleId).isEqualTo(expectedTitleId);
+ }
+
+ @Test
+ public void setHintsRing_aliased_Matches() {
+ assertThat(mController.hintsMatch(
+ NotificationListenerService.HINT_HOST_DISABLE_CALL_EFFECTS, false)).isTrue();
+ }
+
+ @Test
+ public void setHintsRingNotification_aliased_Matches() {
+ assertThat(mController.hintsMatch(NotificationListenerService.HINT_HOST_DISABLE_EFFECTS,
+ false)).isTrue();
+ }
+
+ @Test
+ public void setHintNotification_aliased_Matches() {
+ assertThat(mController
+ .hintsMatch(NotificationListenerService.HINT_HOST_DISABLE_NOTIFICATION_EFFECTS,
+ false)).isTrue();
+ }
+
+ @Test
+ public void setHintsRing_unaliased_Matches() {
+ assertThat(mController.hintsMatch(
+ NotificationListenerService.HINT_HOST_DISABLE_CALL_EFFECTS, true)).isTrue();
+ }
+
+ @Test
+ public void setHintsRingNotification_unaliased_Matches() {
+ assertThat(mController.hintsMatch(NotificationListenerService.HINT_HOST_DISABLE_EFFECTS,
+ true)).isTrue();
+ }
+
+ @Test
+ public void setHintNotification_unaliased_doesNotMatch() {
+ assertThat(mController
+ .hintsMatch(NotificationListenerService.HINT_HOST_DISABLE_NOTIFICATION_EFFECTS,
+ true)).isFalse();
+ }
+
+ @Test
+ public void setRingerModeToVibrate_butNoVibratorAvailable_iconIsSilent() {
+ when(mHelper.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE);
+
+ mController.setPreference(mPreference);
+ mController.setVibrator(null);
+ mController.updateRingerMode();
+
+ assertThat(mController.getMuteIcon()).isEqualTo(mController.mSilentIconId);
+ }
+
+ @Test
+ public void setRingerModeToVibrate_VibratorAvailable_iconIsVibrate() {
+ when(mHelper.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE);
+ when(mVibrator.hasVibrator()).thenReturn(true);
+
+ mController.setPreference(mPreference);
+ mController.setVibrator(mVibrator);
+ mController.updateRingerMode();
+
+ assertThat(mController.getMuteIcon()).isEqualTo(mController.mVibrateIconId);
+ }
+
}
diff --git a/tests/robotests/src/com/android/settings/notification/ShowOnLockscreenNotificationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ShowOnLockscreenNotificationPreferenceControllerTest.java
index 496897f87a9e22c79b4c47388235cf9d10ce1b3c..567c7ff9bc40217d9da99cf033bd58271a299feb 100644
--- a/tests/robotests/src/com/android/settings/notification/ShowOnLockscreenNotificationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ShowOnLockscreenNotificationPreferenceControllerTest.java
@@ -28,6 +28,8 @@ import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.provider.Settings;
+import androidx.preference.PreferenceScreen;
+
import com.android.settings.R;
import com.android.settings.RestrictedListPreference;
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtilsInternal;
@@ -42,11 +44,8 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
-import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
-import androidx.preference.PreferenceScreen;
-
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {ShadowUserManager.class, ShadowRestrictedLockUtilsInternal.class})
public class ShowOnLockscreenNotificationPreferenceControllerTest {
@@ -94,7 +93,7 @@ public class ShowOnLockscreenNotificationPreferenceControllerTest {
assertThat(mPreference.getValue()).isEqualTo(
String.valueOf(R.string.lock_screen_notifs_show_none));
- assertThat(mPreference.getSummary())
+ assertThat(mPreference.getSummary().toString())
.isEqualTo(mContext.getString(R.string.lock_screen_notifs_show_none));
}
@@ -111,7 +110,7 @@ public class ShowOnLockscreenNotificationPreferenceControllerTest {
assertThat(mPreference.getValue()).isEqualTo(
String.valueOf(R.string.lock_screen_notifs_show_alerting));
- assertThat(mPreference.getSummary())
+ assertThat(mPreference.getSummary().toString())
.isEqualTo(mContext.getString(R.string.lock_screen_notifs_show_alerting));
}
@@ -128,20 +127,20 @@ public class ShowOnLockscreenNotificationPreferenceControllerTest {
assertThat(mPreference.getValue()).isEqualTo(
String.valueOf(R.string.lock_screen_notifs_show_all));
- assertThat(mPreference.getSummary())
+ assertThat(mPreference.getSummary().toString())
.isEqualTo(mContext.getString(R.string.lock_screen_notifs_show_all));
}
@Test
- public void updateState_allNotifsOnLockscreen_isDefault() {
+ public void updateState_alertingNotifsOnLockscreen_isDefault() {
// settings don't exist
mController.displayPreference(mScreen);
assertThat(mPreference.getValue()).isEqualTo(
- String.valueOf(R.string.lock_screen_notifs_show_all));
- assertThat(mPreference.getSummary())
- .isEqualTo(mContext.getString(R.string.lock_screen_notifs_show_all));
+ String.valueOf(R.string.lock_screen_notifs_show_alerting));
+ assertThat(mPreference.getSummary().toString())
+ .isEqualTo(mContext.getString(R.string.lock_screen_notifs_show_alerting));
}
@Test
diff --git a/tests/robotests/src/com/android/settings/notification/SoundSettingsTest.java b/tests/robotests/src/com/android/settings/notification/SoundSettingsTest.java
index c2ea6e70105331fb5a67c1e0bd4edb65b74f7da7..9e84883b7e6e8f2a41182e57a1ca36ecfb39edc5 100644
--- a/tests/robotests/src/com/android/settings/notification/SoundSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/notification/SoundSettingsTest.java
@@ -35,6 +35,7 @@ import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
import com.android.settings.testutils.shadow.ShadowDeviceConfig;
import com.android.settings.testutils.shadow.ShadowUserManager;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
@@ -44,8 +45,6 @@ import org.robolectric.util.ReflectionHelpers;
import java.util.List;
-import org.junit.Ignore;
-
@RunWith(RobolectricTestRunner.class)
public class SoundSettingsTest {
@@ -86,4 +85,19 @@ public class SoundSettingsTest {
assertThat(settings.mHandler.hasMessages(SoundSettings.STOP_SAMPLE)).isTrue();
}
+
+ @Test
+ public void notificationVolume_isBetweenRingAndAlarm() {
+ final Context context = spy(RuntimeEnvironment.application);
+ final SoundSettings settings = new SoundSettings();
+ final int xmlId = settings.getPreferenceScreenResId();
+ final List keys = XmlTestUtils.getKeysFromPreferenceXml(context, xmlId);
+
+ int ring = keys.indexOf("ring_volume");
+ int notification = keys.indexOf("notification_volume");
+ int alarm = keys.indexOf("alarm_volume");
+
+ assertThat(ring < notification).isTrue();
+ assertThat(notification < alarm).isTrue();
+ }
}
diff --git a/tests/robotests/src/com/android/settings/notification/app/NotificationsOffPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/NotificationsOffPreferenceControllerTest.java
index 34e94a042f98ff851718403abff84de5e1988ab2..2eebd3a2eabca6fbfa0fea781fee2b0a6dddab7c 100644
--- a/tests/robotests/src/com/android/settings/notification/app/NotificationsOffPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/app/NotificationsOffPreferenceControllerTest.java
@@ -20,6 +20,7 @@ import static android.app.NotificationManager.IMPORTANCE_NONE;
import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@@ -32,6 +33,7 @@ import android.os.UserManager;
import androidx.preference.Preference;
+import com.android.settings.R;
import com.android.settings.notification.NotificationBackend;
import com.google.common.collect.ImmutableList;
@@ -157,4 +159,23 @@ public class NotificationsOffPreferenceControllerTest {
assertThat(pref.getTitle().toString()).contains("app");
assertThat(pref.isSelectable()).isFalse();
}
+
+ @Test
+ public void testUpdateState_whenToggleDisabled() {
+ // Given: the app does not request to post notifications
+ // and it's preference toggle is disabled
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.banned = true;
+ appRow.permissionStateLocked = true;
+ mController.onResume(appRow, null, null, null, null, null, null);
+ Preference pref = new Preference(RuntimeEnvironment.application);
+
+ // When: updateState(Preference preference) is called
+ mController.updateState(pref);
+
+ // Then: title of pref should be app_notifications_not_send_desc
+ assertEquals(
+ RuntimeEnvironment.application.getString(R.string.app_notifications_not_send_desc),
+ pref.getTitle().toString());
+ }
}
diff --git a/tests/robotests/src/com/android/settings/sim/SimSelectNotificationTest.java b/tests/robotests/src/com/android/settings/sim/SimSelectNotificationTest.java
index b33e94ba52ebf2f2b5d66b41bbe337600ead9657..e1b2b4ed84e6053bc78bb2045b3bad855ee5f57a 100644
--- a/tests/robotests/src/com/android/settings/sim/SimSelectNotificationTest.java
+++ b/tests/robotests/src/com/android/settings/sim/SimSelectNotificationTest.java
@@ -143,6 +143,7 @@ public class SimSelectNotificationTest {
when(mSubInfo.getDisplayName()).thenReturn(mFakeDisplayName);
when(mContext.getResources()).thenReturn(mResources);
+ when(mResources.getBoolean(R.bool.config_show_sim_info)).thenReturn(true);
when(mResources.getText(R.string.enable_sending_mms_notification_title))
.thenReturn(mFakeNotificationTitle);
when(mResources.getText(R.string.enable_mms_notification_channel_title))
diff --git a/tests/robotests/src/com/android/settings/sound/AudioOutputSwitchPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/sound/AudioOutputSwitchPreferenceControllerTest.java
index b04a2cd21bfb5ff83723fca36aa993c9a830e7a2..151d1f289c1fc162ea376432216b99fa0be2b753 100644
--- a/tests/robotests/src/com/android/settings/sound/AudioOutputSwitchPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/sound/AudioOutputSwitchPreferenceControllerTest.java
@@ -51,14 +51,16 @@ import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
import com.android.settingslib.bluetooth.A2dpProfile;
import com.android.settingslib.bluetooth.BluetoothCallback;
import com.android.settingslib.bluetooth.BluetoothEventManager;
+import com.android.settingslib.bluetooth.CachedBluetoothDevice;
+import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
import com.android.settingslib.bluetooth.HeadsetProfile;
import com.android.settingslib.bluetooth.HearingAidProfile;
+import com.android.settingslib.bluetooth.LeAudioProfile;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
import org.junit.After;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -71,10 +73,10 @@ import org.robolectric.shadows.ShadowBluetoothDevice;
import org.robolectric.shadows.ShadowPackageManager;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
@RunWith(RobolectricTestRunner.class)
-@Ignore
@Config(shadows = {
ShadowAudioManager.class,
ShadowBluetoothUtils.class,
@@ -102,6 +104,14 @@ public class AudioOutputSwitchPreferenceControllerTest {
private HeadsetProfile mHeadsetProfile;
@Mock
private HearingAidProfile mHearingAidProfile;
+ @Mock
+ private LeAudioProfile mLeAudioProfile;
+ @Mock
+ private CachedBluetoothDeviceManager mCachedDeviceManager;
+ @Mock
+ private CachedBluetoothDevice mCachedBluetoothDeviceL;
+ @Mock
+ private CachedBluetoothDevice mCachedBluetoothDeviceR;
private Context mContext;
private PreferenceScreen mScreen;
@@ -117,8 +127,10 @@ public class AudioOutputSwitchPreferenceControllerTest {
private AudioSwitchPreferenceController mController;
private List mProfileConnectedDevices;
private List mHearingAidActiveDevices;
+ private List mLeAudioActiveDevices;
private List mEmptyDevices;
private ShadowPackageManager mPackageManager;
+ private Collection mCachedDevices;
@Before
public void setUp() {
@@ -133,15 +145,22 @@ public class AudioOutputSwitchPreferenceControllerTest {
when(mLocalBluetoothManager.getEventManager()).thenReturn(mBluetoothEventManager);
when(mLocalBluetoothManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager);
+ when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(mCachedDeviceManager);
when(mLocalBluetoothProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile);
when(mLocalBluetoothProfileManager.getHearingAidProfile()).thenReturn(mHearingAidProfile);
when(mLocalBluetoothProfileManager.getHeadsetProfile()).thenReturn(mHeadsetProfile);
+ when(mLocalBluetoothProfileManager.getLeAudioProfile()).thenReturn(mLeAudioProfile);
mPackageManager = Shadow.extract(mContext.getPackageManager());
mPackageManager.setSystemFeature(PackageManager.FEATURE_BLUETOOTH, true);
mBluetoothManager = mContext.getSystemService(BluetoothManager.class);
mBluetoothAdapter = mBluetoothManager.getAdapter();
+ mCachedDevices = new ArrayList<>();
+ mCachedDevices.add(mCachedBluetoothDeviceL);
+ mCachedDevices.add(mCachedBluetoothDeviceR);
+ when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(mCachedDevices);
+
mBluetoothDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_1));
when(mBluetoothDevice.getName()).thenReturn(TEST_DEVICE_NAME_1);
when(mBluetoothDevice.isConnected()).thenReturn(true);
@@ -156,6 +175,7 @@ public class AudioOutputSwitchPreferenceControllerTest {
mPreference = new ListPreference(mContext);
mProfileConnectedDevices = new ArrayList<>();
mHearingAidActiveDevices = new ArrayList<>(2);
+ mLeAudioActiveDevices = new ArrayList<>();
mEmptyDevices = new ArrayList<>(2);
when(mScreen.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
@@ -391,6 +411,79 @@ public class AudioOutputSwitchPreferenceControllerTest {
assertThat(mEmptyDevices).containsExactly(mBluetoothDevice, mLeftBluetoothHapDevice);
}
+ @Test
+ public void getConnectedLeAudioDevices_connectedLeAudioDevice_shouldAddDeviceToList() {
+ when(mCachedBluetoothDeviceL.getDevice()).thenReturn(mBluetoothDevice);
+ mEmptyDevices.clear();
+ mProfileConnectedDevices.clear();
+ mProfileConnectedDevices.add(mBluetoothDevice);
+ when(mLeAudioProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
+
+ mEmptyDevices.addAll(mController.getConnectedLeAudioDevices());
+
+ assertThat(mEmptyDevices).containsExactly(mBluetoothDevice);
+ }
+
+ @Test
+ public void getConnectedLeAudioDevices_disconnectedLeAudioDevice_shouldNotAddDeviceToList() {
+ BluetoothDevice connectedBtLeAduioDevice =
+ spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_2));
+ when(connectedBtLeAduioDevice.isConnected()).thenReturn(true);
+ BluetoothDevice disconnectedBtLeAduioDevice =
+ spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_3));
+ when(disconnectedBtLeAduioDevice.isConnected()).thenReturn(false);
+ when(mCachedBluetoothDeviceL.getDevice()).thenReturn(mBluetoothDevice);
+ when(mCachedBluetoothDeviceR.getDevice()).thenReturn(connectedBtLeAduioDevice);
+ mEmptyDevices.clear();
+ mProfileConnectedDevices.clear();
+ mProfileConnectedDevices.add(mBluetoothDevice);
+ mProfileConnectedDevices.add(connectedBtLeAduioDevice);
+ mProfileConnectedDevices.add(disconnectedBtLeAduioDevice);
+ when(mLeAudioProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
+
+ mEmptyDevices.addAll(mController.getConnectedLeAudioDevices());
+
+ assertThat(mEmptyDevices).containsExactly(mBluetoothDevice, connectedBtLeAduioDevice);
+ }
+
+ @Test
+ public void getConnectedLeAudioDevices_notInCachedDeviceList_shouldNotAddDeviceToList() {
+ BluetoothDevice connectedBtLeAduioDevice1 =
+ spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_2));
+ when(connectedBtLeAduioDevice1.isConnected()).thenReturn(true);
+ BluetoothDevice connectedBtLeAduioDevice2 =
+ spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_3));
+ when(connectedBtLeAduioDevice2.isConnected()).thenReturn(true);
+ when(mCachedBluetoothDeviceL.getDevice()).thenReturn(mBluetoothDevice);
+ when(mCachedBluetoothDeviceR.getDevice()).thenReturn(connectedBtLeAduioDevice1);
+ mEmptyDevices.clear();
+ mProfileConnectedDevices.clear();
+ mProfileConnectedDevices.add(connectedBtLeAduioDevice1);
+ mProfileConnectedDevices.add(connectedBtLeAduioDevice2);
+ when(mLeAudioProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
+
+ mEmptyDevices.addAll(mController.getConnectedLeAudioDevices());
+
+ assertThat(mEmptyDevices).containsExactly(connectedBtLeAduioDevice1);
+ }
+
+ @Test
+ public void findActiveLeAudioDevice_noActiveDevice_returnNull() {
+ mLeAudioActiveDevices.clear();
+ when(mLeAudioProfile.getActiveDevices()).thenReturn(mLeAudioActiveDevices);
+
+ assertThat(mController.findActiveLeAudioDevice()).isNull();
+ }
+
+ @Test
+ public void findActiveLeAudioDevice_withActiveDevice_returnActiveDevice() {
+ mLeAudioActiveDevices.clear();
+ mLeAudioActiveDevices.add(mBluetoothDevice);
+ when(mLeAudioProfile.getActiveDevices()).thenReturn(mLeAudioActiveDevices);
+
+ assertThat(mController.findActiveLeAudioDevice()).isEqualTo(mBluetoothDevice);
+ }
+
private class AudioSwitchPreferenceControllerTestable extends
AudioSwitchPreferenceController {
AudioSwitchPreferenceControllerTestable(Context context, String key) {
diff --git a/tests/robotests/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceControllerTest.java
index 2580bfd87860544e68f041cdef347703ecaa6069..cc2606b06a24beb2c49c4d4158c5ff6a624f7eb9 100644
--- a/tests/robotests/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceControllerTest.java
@@ -16,6 +16,7 @@
package com.android.settings.sound;
+import static android.media.AudioSystem.DEVICE_OUT_BLE_HEADSET;
import static android.media.AudioSystem.DEVICE_OUT_BLUETOOTH_SCO;
import static android.media.AudioSystem.DEVICE_OUT_HEARING_AID;
@@ -44,29 +45,30 @@ import com.android.settings.bluetooth.Utils;
import com.android.settings.testutils.shadow.ShadowAudioManager;
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
import com.android.settingslib.bluetooth.BluetoothEventManager;
+import com.android.settingslib.bluetooth.CachedBluetoothDevice;
+import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
import com.android.settingslib.bluetooth.HeadsetProfile;
import com.android.settingslib.bluetooth.HearingAidProfile;
+import com.android.settingslib.bluetooth.LeAudioProfile;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
import org.junit.After;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
-import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowBluetoothDevice;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
@RunWith(RobolectricTestRunner.class)
-@Ignore
@Config(shadows = {
ShadowAudioManager.class,
ShadowBluetoothUtils.class,
@@ -78,10 +80,12 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
private static final String TEST_DEVICE_NAME_2 = "Test_HFP_BT_Device_NAME_2";
private static final String TEST_HAP_DEVICE_NAME_1 = "Test_HAP_BT_Device_NAME_1";
private static final String TEST_HAP_DEVICE_NAME_2 = "Test_HAP_BT_Device_NAME_2";
+ private static final String TEST_LE_AUDIO_DEVICE_NAME_1 = "Test_LE_AUDIO_Device_NAME_1";
private static final String TEST_DEVICE_ADDRESS_1 = "00:A1:A1:A1:A1:A1";
private static final String TEST_DEVICE_ADDRESS_2 = "00:B2:B2:B2:B2:B2";
private static final String TEST_DEVICE_ADDRESS_3 = "00:C3:C3:C3:C3:C3";
private static final String TEST_DEVICE_ADDRESS_4 = "00:D4:D4:D4:D4:D4";
+ private static final String TEST_DEVICE_ADDRESS_5 = "00:E5:E5:E5:E5:E5";
private final static long HISYNCID1 = 10;
private final static long HISYNCID2 = 11;
@@ -96,7 +100,15 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
@Mock
private HearingAidProfile mHearingAidProfile;
@Mock
+ private LeAudioProfile mLeAudioProfile;
+ @Mock
private AudioSwitchPreferenceController.AudioSwitchCallback mAudioSwitchPreferenceCallback;
+ @Mock
+ private CachedBluetoothDeviceManager mCachedDeviceManager;
+ @Mock
+ private CachedBluetoothDevice mCachedBluetoothDeviceL;
+ @Mock
+ private CachedBluetoothDevice mCachedBluetoothDeviceR;
private Context mContext;
private PreferenceScreen mScreen;
@@ -113,6 +125,8 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
private HandsFreeProfileOutputPreferenceController mController;
private List mProfileConnectedDevices;
private List mHearingAidActiveDevices;
+ private List mLeAudioActiveDevices;
+ private Collection mCachedDevices;
@Before
public void setUp() {
@@ -127,26 +141,37 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
when(mLocalBluetoothManager.getEventManager()).thenReturn(mBluetoothEventManager);
when(mLocalBluetoothManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager);
+ when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(mCachedDeviceManager);
when(mLocalBluetoothProfileManager.getHeadsetProfile()).thenReturn(mHeadsetProfile);
when(mLocalBluetoothProfileManager.getHearingAidProfile()).thenReturn(mHearingAidProfile);
+ when(mLocalBluetoothProfileManager.getLeAudioProfile()).thenReturn(mLeAudioProfile);
mBluetoothManager = mContext.getSystemService(BluetoothManager.class);
mBluetoothAdapter = mBluetoothManager.getAdapter();
+ mCachedDevices = new ArrayList<>();
+ mCachedDevices.add(mCachedBluetoothDeviceL);
+ mCachedDevices.add(mCachedBluetoothDeviceR);
+ when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(mCachedDevices);
+
mBluetoothDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_1));
when(mBluetoothDevice.getName()).thenReturn(TEST_DEVICE_NAME_1);
+ when(mBluetoothDevice.getAlias()).thenReturn(TEST_DEVICE_NAME_1);
when(mBluetoothDevice.isConnected()).thenReturn(true);
mSecondBluetoothDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_2));
when(mSecondBluetoothDevice.getName()).thenReturn(TEST_DEVICE_NAME_2);
+ when(mSecondBluetoothDevice.getAlias()).thenReturn(TEST_DEVICE_NAME_2);
when(mSecondBluetoothDevice.isConnected()).thenReturn(true);
mLeftBluetoothHapDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_3));
when(mLeftBluetoothHapDevice.getName()).thenReturn(TEST_HAP_DEVICE_NAME_1);
+ when(mLeftBluetoothHapDevice.getAlias()).thenReturn(TEST_HAP_DEVICE_NAME_1);
when(mLeftBluetoothHapDevice.isConnected()).thenReturn(true);
mRightBluetoothHapDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_4));
when(mRightBluetoothHapDevice.getName()).thenReturn(TEST_HAP_DEVICE_NAME_2);
+ when(mRightBluetoothHapDevice.getAlias()).thenReturn(TEST_HAP_DEVICE_NAME_2);
when(mRightBluetoothHapDevice.isConnected()).thenReturn(true);
mController = new HandsFreeProfileOutputPreferenceController(mContext, TEST_KEY);
@@ -154,6 +179,7 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
mPreference = new ListPreference(mContext);
mProfileConnectedDevices = new ArrayList<>();
mHearingAidActiveDevices = new ArrayList<>(2);
+ mLeAudioActiveDevices = new ArrayList<>();
when(mScreen.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
when(mScreen.getContext()).thenReturn(mContext);
@@ -245,7 +271,6 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
* Preference summary should be the activated device name
*/
@Test
- @Ignore
public void updateState_oneHeadsetsAvailableAndActivated_shouldSetDeviceName() {
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLUETOOTH_SCO);
@@ -267,7 +292,6 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
* Preference summary should be the activated device name
*/
@Test
- @Ignore
public void updateState_moreThanOneHfpBtDevicesAreAvailable_shouldSetActivatedDeviceName() {
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLUETOOTH_SCO);
@@ -328,7 +352,6 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
* Preference summary should be the activated device name
*/
@Test
- @Ignore
public void updateState_oneHapBtDeviceAreAvailable_shouldSetActivatedDeviceName() {
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
@@ -353,7 +376,6 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
* Preference summary should be the activated device name
*/
@Test
- @Ignore
public void updateState_moreThanOneHapBtDevicesAreAvailable_shouldSetActivatedDeviceName() {
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
@@ -382,7 +404,6 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
* ConnectedDevice should not contain second HAP device with same HisyncId
*/
@Test
- @Ignore
public void updateState_hapBtDeviceWithSameId_shouldSetActivatedDeviceName() {
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
@@ -416,7 +437,6 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
* ConnectedDevice should not contain second HAP device with same HisyncId
*/
@Test
- @Ignore
public void updateState_hapBtDeviceWithSameIdButDifferentOrder_shouldSetActivatedDeviceName() {
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
@@ -449,7 +469,6 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
* ConnectedDevice should contain both HAP device with different HisyncId
*/
@Test
- @Ignore
public void updateState_hapBtDeviceWithDifferentId_shouldSetActivatedDeviceName() {
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
@@ -473,6 +492,26 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
mLeftBluetoothHapDevice, mRightBluetoothHapDevice);
}
+ @Test
+ public void updateState_leAudioDeviceActive_shouldSetActivatedDeviceName() {
+ mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
+ mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLE_HEADSET);
+ when(mCachedBluetoothDeviceL.getDevice()).thenReturn(mBluetoothDevice);
+ when(mBluetoothDevice.getName()).thenReturn(TEST_LE_AUDIO_DEVICE_NAME_1);
+ when(mBluetoothDevice.getAlias()).thenReturn(TEST_LE_AUDIO_DEVICE_NAME_1);
+ mProfileConnectedDevices.clear();
+ mProfileConnectedDevices.add(mBluetoothDevice);
+ mLeAudioActiveDevices.clear();
+ mLeAudioActiveDevices.add(mBluetoothDevice);
+ when(mLeAudioProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
+ when(mLeAudioProfile.getActiveDevices()).thenReturn(mLeAudioActiveDevices);
+
+ mController.updateState(mPreference);
+
+ assertThat(mPreference.isVisible()).isTrue();
+ assertThat(mPreference.getSummary()).isEqualTo(mBluetoothDevice.getName());
+ }
+
@Test
public void findActiveDevice_onlyHeadsetDeviceActive_returnHeadsetDevice() {
when(mLocalBluetoothProfileManager.getHearingAidProfile()).thenReturn(null);
@@ -489,12 +528,60 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
assertThat(mController.findActiveDevice()).isNull();
}
+ @Test
+ public void findActiveDevice_allProfilesWithActiveDevice_returnHADevice() {
+ BluetoothDevice btLeDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_5));
+ when(btLeDevice.getName()).thenReturn(TEST_LE_AUDIO_DEVICE_NAME_1);
+ mController.mConnectedDevices.clear();
+ mController.mConnectedDevices.add(mBluetoothDevice);
+ mController.mConnectedDevices.add(mLeftBluetoothHapDevice);
+ mController.mConnectedDevices.add(btLeDevice);
+ mLeAudioActiveDevices.clear();
+ mLeAudioActiveDevices.add(btLeDevice);
+ mHearingAidActiveDevices.clear();
+ mHearingAidActiveDevices.add(mLeftBluetoothHapDevice);
+ when(mHearingAidProfile.getActiveDevices()).thenReturn(mHearingAidActiveDevices);
+ when(mHearingAidProfile.getHiSyncId(mLeftBluetoothHapDevice)).thenReturn(HISYNCID1);
+ when(mHeadsetProfile.getActiveDevice()).thenReturn(mBluetoothDevice);
+ when(mLeAudioProfile.getActiveDevices()).thenReturn(mLeAudioActiveDevices);
+
+ assertThat(mController.findActiveDevice()).isEqualTo(mLeftBluetoothHapDevice);
+ }
+
+ @Test
+ public void findActiveDevice_headsetDeviceAndLeAudioDeviceActive_returnLeAudioDevice() {
+ BluetoothDevice btLeDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_5));
+ when(btLeDevice.getName()).thenReturn(TEST_LE_AUDIO_DEVICE_NAME_1);
+ mLeAudioActiveDevices.clear();
+ mLeAudioActiveDevices.add(btLeDevice);
+ mHearingAidActiveDevices.clear();
+ when(mHearingAidProfile.getActiveDevices()).thenReturn(mHearingAidActiveDevices);
+ when(mHeadsetProfile.getActiveDevice()).thenReturn(mBluetoothDevice);
+ when(mLeAudioProfile.getActiveDevices()).thenReturn(mLeAudioActiveDevices);
+
+ assertThat(mController.findActiveDevice()).isEqualTo(btLeDevice);
+ }
+
+ @Test
+ public void findActiveDevice_onlyLeAudioDeviceActive_returnLeAudioDevice() {
+ BluetoothDevice btLeDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_5));
+ when(btLeDevice.getName()).thenReturn(TEST_LE_AUDIO_DEVICE_NAME_1);
+ mLeAudioActiveDevices.clear();
+ mLeAudioActiveDevices.add(btLeDevice);
+ mHearingAidActiveDevices.clear();
+ when(mHearingAidProfile.getActiveDevices()).thenReturn(mHearingAidActiveDevices);
+ when(mHeadsetProfile.getActiveDevice()).thenReturn(null);
+ when(mLeAudioProfile.getActiveDevices()).thenReturn(mLeAudioActiveDevices);
+
+ assertThat(mController.findActiveDevice()).isEqualTo(btLeDevice);
+ }
+
+
/**
* One Bluetooth devices are available, and select the device.
* Preference summary should be device name.
*/
@Test
- @Ignore
public void onPreferenceChange_toBtDevice_shouldSetBtDeviceName() {
mController.mConnectedDevices.clear();
mController.mConnectedDevices.add(mBluetoothDevice);
@@ -509,16 +596,10 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
* Preference summary should be second device name.
*/
@Test
- @Ignore
public void onPreferenceChange_toBtDevices_shouldSetSecondBtDeviceName() {
- ShadowBluetoothDevice shadowBluetoothDevice;
- BluetoothDevice secondBluetoothDevice;
- secondBluetoothDevice = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_2);
- shadowBluetoothDevice = Shadows.shadowOf(secondBluetoothDevice);
- shadowBluetoothDevice.setName(TEST_DEVICE_NAME_2);
mController.mConnectedDevices.clear();
mController.mConnectedDevices.add(mBluetoothDevice);
- mController.mConnectedDevices.add(secondBluetoothDevice);
+ mController.mConnectedDevices.add(mSecondBluetoothDevice);
mController.onPreferenceChange(mPreference, TEST_DEVICE_ADDRESS_2);
diff --git a/tests/robotests/src/com/android/settings/sound/MediaOutputPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/sound/MediaOutputPreferenceControllerTest.java
index 10471cb405bc9a57bd37c16d152a3081afa91a40..5a92a0838a1ed839c48ab673833dac35e1fddaab 100644
--- a/tests/robotests/src/com/android/settings/sound/MediaOutputPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/sound/MediaOutputPreferenceControllerTest.java
@@ -16,6 +16,7 @@
package com.android.settings.sound;
+import static android.media.AudioSystem.DEVICE_OUT_BLE_HEADSET;
import static android.media.AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP;
import static android.media.AudioSystem.DEVICE_OUT_EARPIECE;
import static android.media.AudioSystem.DEVICE_OUT_HEARING_AID;
@@ -55,14 +56,16 @@ import com.android.settings.testutils.shadow.ShadowAudioManager;
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
import com.android.settingslib.bluetooth.A2dpProfile;
import com.android.settingslib.bluetooth.BluetoothEventManager;
+import com.android.settingslib.bluetooth.CachedBluetoothDevice;
+import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
import com.android.settingslib.bluetooth.HearingAidProfile;
+import com.android.settingslib.bluetooth.LeAudioProfile;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
import com.android.settingslib.media.MediaOutputConstants;
import org.junit.After;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
@@ -76,10 +79,10 @@ import org.robolectric.shadows.ShadowBluetoothDevice;
import org.robolectric.shadows.ShadowPackageManager;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
@RunWith(RobolectricTestRunner.class)
-@Ignore
@Config(shadows = {
ShadowAudioManager.class,
ShadowBluetoothUtils.class,
@@ -91,10 +94,12 @@ public class MediaOutputPreferenceControllerTest {
private static final String TEST_DEVICE_NAME_2 = "Test_A2DP_BT_Device_NAME_2";
private static final String TEST_HAP_DEVICE_NAME_1 = "Test_HAP_BT_Device_NAME_1";
private static final String TEST_HAP_DEVICE_NAME_2 = "Test_HAP_BT_Device_NAME_2";
+ private static final String TEST_LE_AUDIO_DEVICE_NAME_1 = "Test_LE_AUDIO_Device_NAME_1";
private static final String TEST_DEVICE_ADDRESS_1 = "00:A1:A1:A1:A1:A1";
private static final String TEST_DEVICE_ADDRESS_2 = "00:B2:B2:B2:B2:B2";
private static final String TEST_DEVICE_ADDRESS_3 = "00:C3:C3:C3:C3:C3";
private static final String TEST_DEVICE_ADDRESS_4 = "00:D4:D4:D4:D4:D4";
+ private static final String TEST_DEVICE_ADDRESS_5 = "00:E5:E5:E5:E5:E5";
private static final String TEST_PACKAGE_NAME = "com.test.packagename";
private static final String TEST_APPLICATION_LABEL = "APP Test Label";
@@ -109,11 +114,19 @@ public class MediaOutputPreferenceControllerTest {
@Mock
private HearingAidProfile mHearingAidProfile;
@Mock
+ private LeAudioProfile mLeAudioProfile;
+ @Mock
private AudioSwitchPreferenceController.AudioSwitchCallback mAudioSwitchPreferenceCallback;
@Mock
private MediaSessionManager mMediaSessionManager;
@Mock
private MediaController mMediaController;
+ @Mock
+ private CachedBluetoothDeviceManager mCachedDeviceManager;
+ @Mock
+ private CachedBluetoothDevice mCachedBluetoothDeviceL;
+ @Mock
+ private CachedBluetoothDevice mCachedBluetoothDeviceR;
private Context mContext;
private PreferenceScreen mScreen;
@@ -130,6 +143,7 @@ public class MediaOutputPreferenceControllerTest {
private MediaOutputPreferenceController mController;
private List mProfileConnectedDevices;
private List mHearingAidActiveDevices;
+ private List mLeAudioActiveDevices;
private List mMediaControllers = new ArrayList<>();
private MediaController.PlaybackInfo mPlaybackInfo;
private PlaybackState mPlaybackState;
@@ -137,6 +151,7 @@ public class MediaOutputPreferenceControllerTest {
private ApplicationInfo mAppInfo;
private PackageInfo mPackageInfo;
private PackageStats mPackageStats;
+ private Collection mCachedDevices;
@Before
public void setUp() {
@@ -168,14 +183,22 @@ public class MediaOutputPreferenceControllerTest {
when(mLocalBluetoothManager.getEventManager()).thenReturn(mBluetoothEventManager);
when(mLocalBluetoothManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager);
+ when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(mCachedDeviceManager);
when(mLocalBluetoothProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile);
when(mLocalBluetoothProfileManager.getHearingAidProfile()).thenReturn(mHearingAidProfile);
+ when(mLocalBluetoothProfileManager.getLeAudioProfile()).thenReturn(mLeAudioProfile);
mBluetoothManager = mContext.getSystemService(BluetoothManager.class);
mBluetoothAdapter = mBluetoothManager.getAdapter();
+ mCachedDevices = new ArrayList<>();
+ mCachedDevices.add(mCachedBluetoothDeviceL);
+ mCachedDevices.add(mCachedBluetoothDeviceR);
+ when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(mCachedDevices);
+
mBluetoothDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_1));
when(mBluetoothDevice.getName()).thenReturn(TEST_DEVICE_NAME_1);
+ when(mBluetoothDevice.getAlias()).thenReturn(TEST_DEVICE_NAME_1);
when(mBluetoothDevice.isConnected()).thenReturn(true);
mSecondBluetoothDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_2));
@@ -184,6 +207,7 @@ public class MediaOutputPreferenceControllerTest {
mLeftBluetoothHapDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_3));
when(mLeftBluetoothHapDevice.getName()).thenReturn(TEST_HAP_DEVICE_NAME_1);
+ when(mLeftBluetoothHapDevice.getAlias()).thenReturn(TEST_HAP_DEVICE_NAME_1);
when(mLeftBluetoothHapDevice.isConnected()).thenReturn(true);
mRightBluetoothHapDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_4));
@@ -195,6 +219,7 @@ public class MediaOutputPreferenceControllerTest {
mPreference = new Preference(mContext);
mProfileConnectedDevices = new ArrayList<>();
mHearingAidActiveDevices = new ArrayList<>(2);
+ mLeAudioActiveDevices = new ArrayList<>();
when(mScreen.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
when(mScreen.getContext()).thenReturn(mContext);
@@ -234,7 +259,6 @@ public class MediaOutputPreferenceControllerTest {
* Preference summary should be device's name
*/
@Test
- @Ignore
public void updateState_withActiveBtDevice_setActivatedDeviceName() {
mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLUETOOTH_A2DP);
mAudioManager.setMode(AudioManager.MODE_NORMAL);
@@ -254,7 +278,6 @@ public class MediaOutputPreferenceControllerTest {
* Preference summary should be device's name
*/
@Test
- @Ignore
public void updateState_withActiveHADevice_setActivatedDeviceName() {
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
mAudioManager.setMode(AudioManager.MODE_NORMAL);
@@ -269,6 +292,26 @@ public class MediaOutputPreferenceControllerTest {
}
+ @Test
+ public void updateState_withActiveLeAudioDevice_setActivatedDeviceName() {
+ mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLE_HEADSET);
+ mAudioManager.setMode(AudioManager.MODE_NORMAL);
+ when(mCachedBluetoothDeviceL.getDevice()).thenReturn(mBluetoothDevice);
+ when(mCachedBluetoothDeviceR.getDevice()).thenReturn(mSecondBluetoothDevice);
+ when(mBluetoothDevice.getAlias()).thenReturn(TEST_LE_AUDIO_DEVICE_NAME_1);
+ mProfileConnectedDevices.clear();
+ mProfileConnectedDevices.add(mBluetoothDevice);
+ mProfileConnectedDevices.add(mSecondBluetoothDevice);
+ mLeAudioActiveDevices.clear();
+ mLeAudioActiveDevices.add(mBluetoothDevice);
+ when(mLeAudioProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
+ when(mLeAudioProfile.getActiveDevices()).thenReturn(mLeAudioActiveDevices);
+
+ assertThat(mPreference.getSummary()).isNull();
+ mController.updateState(mPreference);
+ assertThat(mPreference.getSummary()).isEqualTo(TEST_LE_AUDIO_DEVICE_NAME_1);
+ }
+
@Test
public void updateState_noActiveLocalPlayback_noTitle() {
mPlaybackState = new PlaybackState.Builder()
@@ -350,6 +393,49 @@ public class MediaOutputPreferenceControllerTest {
assertThat(mController.findActiveDevice()).isNull();
}
+ @Test
+ public void findActiveDevice_allProfilesWithActiveDevice_returnHADevice() {
+ BluetoothDevice btLeDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_5));
+ when(btLeDevice.getName()).thenReturn(TEST_LE_AUDIO_DEVICE_NAME_1);
+ mLeAudioActiveDevices.clear();
+ mLeAudioActiveDevices.add(btLeDevice);
+ mHearingAidActiveDevices.clear();
+ mHearingAidActiveDevices.add(mLeftBluetoothHapDevice);
+ when(mHearingAidProfile.getActiveDevices()).thenReturn(mHearingAidActiveDevices);
+ when(mA2dpProfile.getActiveDevice()).thenReturn(mBluetoothDevice);
+ when(mLeAudioProfile.getActiveDevices()).thenReturn(mLeAudioActiveDevices);
+
+ assertThat(mController.findActiveDevice()).isEqualTo(mLeftBluetoothHapDevice);
+ }
+
+ @Test
+ public void findActiveDevice_a2dpDeviceAndLeAudioDeviceActive_returnLeAudioDevice() {
+ BluetoothDevice btLeDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_5));
+ when(btLeDevice.getName()).thenReturn(TEST_LE_AUDIO_DEVICE_NAME_1);
+ mLeAudioActiveDevices.clear();
+ mLeAudioActiveDevices.add(btLeDevice);
+ mHearingAidActiveDevices.clear();
+ when(mHearingAidProfile.getActiveDevices()).thenReturn(mHearingAidActiveDevices);
+ when(mA2dpProfile.getActiveDevice()).thenReturn(mBluetoothDevice);
+ when(mLeAudioProfile.getActiveDevices()).thenReturn(mLeAudioActiveDevices);
+
+ assertThat(mController.findActiveDevice()).isEqualTo(btLeDevice);
+ }
+
+ @Test
+ public void findActiveDevice_onlyLeAudioDeviceActive_returnLeAudioDevice() {
+ BluetoothDevice btLeDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_5));
+ when(btLeDevice.getName()).thenReturn(TEST_LE_AUDIO_DEVICE_NAME_1);
+ mLeAudioActiveDevices.clear();
+ mLeAudioActiveDevices.add(btLeDevice);
+ mHearingAidActiveDevices.clear();
+ when(mHearingAidProfile.getActiveDevices()).thenReturn(mHearingAidActiveDevices);
+ when(mA2dpProfile.getActiveDevice()).thenReturn(null);
+ when(mLeAudioProfile.getActiveDevices()).thenReturn(mLeAudioActiveDevices);
+
+ assertThat(mController.findActiveDevice()).isEqualTo(btLeDevice);
+ }
+
private void initPackage() {
mShadowPackageManager = Shadows.shadowOf(mContext.getPackageManager());
mAppInfo = new ApplicationInfo();
diff --git a/tests/robotests/src/com/android/settings/survey/SurveyMixinTest.java b/tests/robotests/src/com/android/settings/survey/SurveyMixinTest.java
index 0962d299b4f73e6d7df3258300740b12a9ac3d3f..8f4326802eec360613ae773cf54716e0d4a1126a 100644
--- a/tests/robotests/src/com/android/settings/survey/SurveyMixinTest.java
+++ b/tests/robotests/src/com/android/settings/survey/SurveyMixinTest.java
@@ -1,20 +1,12 @@
package com.android.settings.survey;
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import android.content.BroadcastReceiver;
import android.content.Context;
-import android.content.IntentFilter;
import androidx.fragment.app.FragmentActivity;
-import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import com.android.settings.core.InstrumentedPreferenceFragment;
import com.android.settings.overlay.SurveyFeatureProvider;
@@ -28,22 +20,15 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
-import org.robolectric.util.ReflectionHelpers;
-
-import java.util.ArrayList;
-import java.util.HashMap;
@RunWith(RobolectricTestRunner.class)
public class SurveyMixinTest {
private static final String FAKE_KEY = "fake_key";
- private static final String FAKE_SURVEY_ID = "fake_id";
private Context mContext;
private SurveyFeatureProvider mProvider;
@Mock
- private BroadcastReceiver mReceiver;
- @Mock
private InstrumentedPreferenceFragment mFragment;
@Before
@@ -52,99 +37,16 @@ public class SurveyMixinTest {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mProvider = FakeFeatureFactory.setupForTest().getSurveyFeatureProvider(mContext);
- when(mProvider.getSurveyId(any(), eq(FAKE_KEY))).thenReturn(FAKE_SURVEY_ID);
}
@Test
- public void onResume_triesRegisteringReceiverAndDownloadingWhenNoSurveyDetected() {
- // Pretend there is no survey in memory
- when(mProvider.getSurveyExpirationDate(any(), any())).thenReturn(-1L);
-
+ public void onResume_noActionIfActivityDoesNotExist() {
// Pretend we are an activity that is starting up
FragmentActivity temp = Robolectric.setupActivity(FragmentActivity.class);
- when(mFragment.getActivity()).thenReturn(temp);
- SurveyMixin mixin = new SurveyMixin(mFragment, FAKE_KEY);
- mixin.onResume();
-
- // Verify that a download was attempted
- verify(mProvider, times(1)).downloadSurvey(any(), any(), any());
- // Verify that we registered a receiver for download completion broadcasts
- verify(mProvider, times(1)).createAndRegisterReceiver(any());
- // Verify we did not try to show a survey
- verify(mProvider, never()).showSurveyIfAvailable(any(), any());
- }
-
- @Test
- public void onResume_triesShowingSurveyWhenOneIsPresent() {
- // Pretend there is a survey in memory
- when(mProvider.getSurveyExpirationDate(any(), any())).thenReturn(0L);
-
- // Pretend we are an activity that is starting up
- FragmentActivity temp = Robolectric.setupActivity(FragmentActivity.class);
- when(mFragment.getActivity()).thenReturn(temp);
- SurveyMixin mixin = new SurveyMixin(mFragment, FAKE_KEY);
- mixin.onResume();
-
- // Verify that a download was not attempted
- verify(mProvider, never()).downloadSurvey(any(), any(), any());
- // Verify that we did not register a receiver
- verify(mProvider, never()).createAndRegisterReceiver(any());
- // Verify we tried to show a survey
- verify(mProvider, times(1)).showSurveyIfAvailable(any(), any());
- }
-
- @Test
- public void onResume_doesNothingWhenActivityIsNull() {
- // Pretend the activity died somewhere in the process
when(mFragment.getActivity()).thenReturn(null);
SurveyMixin mixin = new SurveyMixin(mFragment, FAKE_KEY);
mixin.onResume();
- // Verify we don't try showing or downloading a survey
- verify(mProvider, never()).showSurveyIfAvailable(any(), any());
- verify(mProvider, never()).downloadSurvey(any(), any(), any());
- }
-
- @Test
- public void onPause_removesReceiverIfPreviouslySet() {
- // Pretend there is a survey in memory
- when(mProvider.getSurveyExpirationDate(any(), any())).thenReturn(-1L);
-
- // Pretend we are an activity that starts and stops
- FragmentActivity temp = Robolectric.setupActivity(FragmentActivity.class);
- when(mFragment.getActivity()).thenReturn(temp);
- when(mProvider.createAndRegisterReceiver(any())).thenReturn(mReceiver);
- LocalBroadcastManager manager = LocalBroadcastManager.getInstance(temp);
- SurveyMixin mixin = new SurveyMixin(mFragment, FAKE_KEY);
- mixin.onResume();
- manager.registerReceiver(mReceiver, new IntentFilter());
- mixin.onPause();
-
- // Verify we remove the receiver
- HashMap> map =
- ReflectionHelpers.getField(manager, "mReceivers");
- assertThat(map.containsKey(mReceiver)).isFalse();
- }
-
- @Test
- public void onPause_doesNothingWhenActivityOrReceiverNull() {
- // Pretend there is a survey in memory
- when(mProvider.getSurveyExpirationDate(any(), any())).thenReturn(-1L);
-
- // Pretend we are an activity that fails to create a receiver properly
- FragmentActivity temp = Robolectric.setupActivity(FragmentActivity.class);
- when(mFragment.getActivity()).thenReturn(temp);
- SurveyMixin mixin = new SurveyMixin(mFragment, FAKE_KEY);
- mixin.onPause();
-
- // Verify we do nothing;
- verify(mProvider, never()).showSurveyIfAvailable(any(), any());
-
- // pretend the activity died before onPause
- when(mFragment.getActivity()).thenReturn(null);
- mixin.onPause();
-
- // Verify we do nothing
- verify(mProvider, never()).showSurveyIfAvailable(any(), any());
+ verify(mProvider, times(0)).sendActivityIfAvailable(FAKE_KEY);
}
}
diff --git a/tests/robotests/src/com/android/settings/testutils/BatteryTestUtils.java b/tests/robotests/src/com/android/settings/testutils/BatteryTestUtils.java
index e4e26d2c531818ee90f9579f9c328a498315feb3..a6f24309f525e47c68e5058d666c188c11392505 100644
--- a/tests/robotests/src/com/android/settings/testutils/BatteryTestUtils.java
+++ b/tests/robotests/src/com/android/settings/testutils/BatteryTestUtils.java
@@ -37,7 +37,7 @@ public class BatteryTestUtils {
BatteryManager.BATTERY_STATUS_DISCHARGING);
}
- private static Intent getCustomBatteryIntent(int plugged, int level, int scale, int status) {
+ public static Intent getCustomBatteryIntent(int plugged, int level, int scale, int status) {
Intent intent = new Intent();
intent.putExtra(BatteryManager.EXTRA_PLUGGED, plugged);
intent.putExtra(BatteryManager.EXTRA_LEVEL, level);
diff --git a/tests/robotests/src/com/android/settings/testutils/FakeFeatureFactory.java b/tests/robotests/src/com/android/settings/testutils/FakeFeatureFactory.java
index 2f248320ae5b7ad63c9cb47645df956fe7b27b1f..518aee9d23a7d535365bdafd2a18121f68f1d731 100644
--- a/tests/robotests/src/com/android/settings/testutils/FakeFeatureFactory.java
+++ b/tests/robotests/src/com/android/settings/testutils/FakeFeatureFactory.java
@@ -47,7 +47,6 @@ import com.android.settings.security.SecurityFeatureProvider;
import com.android.settings.security.SecuritySettingsFeatureProvider;
import com.android.settings.slices.SlicesFeatureProvider;
import com.android.settings.users.UserFeatureProvider;
-import com.android.settings.vpn2.AdvancedVpnFeatureProvider;
import com.android.settings.wifi.WifiTrackerLibProvider;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
@@ -88,7 +87,6 @@ public class FakeFeatureFactory extends FeatureFactory {
public SecuritySettingsFeatureProvider securitySettingsFeatureProvider;
public AccessibilitySearchFeatureProvider mAccessibilitySearchFeatureProvider;
public AccessibilityMetricsFeatureProvider mAccessibilityMetricsFeatureProvider;
- public AdvancedVpnFeatureProvider mAdvancedVpnFeatureProvider;
/**
* Call this in {@code @Before} method of the test class to use fake factory.
@@ -138,7 +136,6 @@ public class FakeFeatureFactory extends FeatureFactory {
securitySettingsFeatureProvider = mock(SecuritySettingsFeatureProvider.class);
mAccessibilitySearchFeatureProvider = mock(AccessibilitySearchFeatureProvider.class);
mAccessibilityMetricsFeatureProvider = mock(AccessibilityMetricsFeatureProvider.class);
- mAdvancedVpnFeatureProvider = mock(AdvancedVpnFeatureProvider.class);
}
@Override
@@ -275,9 +272,4 @@ public class FakeFeatureFactory extends FeatureFactory {
public AccessibilityMetricsFeatureProvider getAccessibilityMetricsFeatureProvider() {
return mAccessibilityMetricsFeatureProvider;
}
-
- @Override
- public AdvancedVpnFeatureProvider getAdvancedVpnFeatureProvider() {
- return mAdvancedVpnFeatureProvider;
- }
}
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowUtils.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowUtils.java
index 40cb25bfb8320608071f507fb0e2dba78a08bb08..5f8c434fc9fdb5d216b770343013d6d098dfdfd5 100644
--- a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowUtils.java
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowUtils.java
@@ -22,6 +22,7 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
+import android.hardware.face.FaceManager;
import android.hardware.fingerprint.FingerprintManager;
import android.os.UserHandle;
import android.os.UserManager;
@@ -39,6 +40,7 @@ import java.util.Map;
public class ShadowUtils {
private static FingerprintManager sFingerprintManager = null;
+ private static FaceManager sFaceManager = null;
private static boolean sIsUserAMonkey;
private static boolean sIsDemoUser;
private static ComponentName sDeviceOwnerComponentName;
@@ -63,6 +65,15 @@ public class ShadowUtils {
sFingerprintManager = fingerprintManager;
}
+ @Implementation
+ protected static FaceManager getFaceManagerOrNull(Context context) {
+ return sFaceManager;
+ }
+
+ public static void setFaceManager(FaceManager faceManager) {
+ sFaceManager = faceManager;
+ }
+
public static void reset() {
sFingerprintManager = null;
sIsUserAMonkey = false;
diff --git a/tests/robotests/src/com/android/settings/users/TimeoutToUserZeroPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/users/TimeoutToDockUserPreferenceControllerTest.java
similarity index 87%
rename from tests/robotests/src/com/android/settings/users/TimeoutToUserZeroPreferenceControllerTest.java
rename to tests/robotests/src/com/android/settings/users/TimeoutToDockUserPreferenceControllerTest.java
index e284d906847e829944410ddaaef74afc36abf74d..774117f86e00d8d9954867c7785dc10acf02061b 100644
--- a/tests/robotests/src/com/android/settings/users/TimeoutToUserZeroPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/users/TimeoutToDockUserPreferenceControllerTest.java
@@ -16,7 +16,7 @@
package com.android.settings.users;
-import static android.provider.Settings.Secure.TIMEOUT_TO_USER_ZERO;
+import static android.provider.Settings.Secure.TIMEOUT_TO_DOCK_USER;
import static com.google.common.truth.Truth.assertThat;
@@ -45,12 +45,12 @@ import org.robolectric.annotation.Config;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {ShadowSecureSettings.class, ShadowUserHandle.class})
-public class TimeoutToUserZeroPreferenceControllerTest {
+public class TimeoutToDockUserPreferenceControllerTest {
private Context mContext;
private Resources mResources;
- private TimeoutToUserZeroPreferenceController mController;
+ private TimeoutToDockUserPreferenceController mController;
- private static final String FAKE_PREFERENCE_KEY = "timeout_to_user_zero_preference";
+ private static final String FAKE_PREFERENCE_KEY = "timeout_to_dock_user_preference";
private String[] mEntries;
private String[] mValues;
@@ -62,15 +62,15 @@ public class TimeoutToUserZeroPreferenceControllerTest {
doReturn(mResources).when(mContext).getResources();
mEntries = mResources.getStringArray(
- R.array.switch_to_user_zero_when_docked_timeout_entries);
+ R.array.switch_to_dock_user_when_docked_timeout_entries);
mValues = mResources.getStringArray(
- R.array.switch_to_user_zero_when_docked_timeout_values);
+ R.array.switch_to_dock_user_when_docked_timeout_values);
- mController = new TimeoutToUserZeroPreferenceController(mContext, FAKE_PREFERENCE_KEY);
+ mController = new TimeoutToDockUserPreferenceController(mContext, FAKE_PREFERENCE_KEY);
// Feature enabled.
when(mResources.getBoolean(
- com.android.internal.R.bool.config_enableTimeoutToUserZeroWhenDocked)).thenReturn(
+ com.android.internal.R.bool.config_enableTimeoutToDockUserWhenDocked)).thenReturn(
true);
// Multi-user feature enabled.
@@ -89,7 +89,7 @@ public class TimeoutToUserZeroPreferenceControllerTest {
@Test
public void getAvailabilityStatus_featureFlagDisabled_returnUnsupportedOnDevice() {
when(mResources.getBoolean(
- com.android.internal.R.bool.config_enableTimeoutToUserZeroWhenDocked)).thenReturn(
+ com.android.internal.R.bool.config_enableTimeoutToDockUserWhenDocked)).thenReturn(
false);
assertThat(mController.getAvailabilityStatus()).isEqualTo(
@@ -121,15 +121,16 @@ public class TimeoutToUserZeroPreferenceControllerTest {
@Test
public void getSummary_settingNotSet() {
- Settings.Secure.putStringForUser(mContext.getContentResolver(), TIMEOUT_TO_USER_ZERO,
+ Settings.Secure.putStringForUser(mContext.getContentResolver(), TIMEOUT_TO_DOCK_USER,
null, UserHandle.myUserId());
- assertThat(mController.getSummary().toString()).isEqualTo(mEntries[0]);
+ assertThat(mController.getSummary().toString()).isEqualTo(
+ mEntries[TimeoutToDockUserSettings.DEFAULT_TIMEOUT_SETTING_VALUE_INDEX]);
}
@Test
public void getSummary_setToNever() {
- Settings.Secure.putStringForUser(mContext.getContentResolver(), TIMEOUT_TO_USER_ZERO,
+ Settings.Secure.putStringForUser(mContext.getContentResolver(), TIMEOUT_TO_DOCK_USER,
mValues[0], UserHandle.myUserId());
assertThat(mController.getSummary().toString()).isEqualTo(mEntries[0]);
@@ -137,7 +138,7 @@ public class TimeoutToUserZeroPreferenceControllerTest {
@Test
public void getSummary_setToOneMinute() {
- Settings.Secure.putStringForUser(mContext.getContentResolver(), TIMEOUT_TO_USER_ZERO,
+ Settings.Secure.putStringForUser(mContext.getContentResolver(), TIMEOUT_TO_DOCK_USER,
mValues[1], UserHandle.myUserId());
assertThat(mController.getSummary().toString()).isEqualTo(mEntries[1]);
diff --git a/tests/robotests/src/com/android/settings/users/TimeoutToUserZeroSettingsTest.java b/tests/robotests/src/com/android/settings/users/TimeoutToDockUserSettingsTest.java
similarity index 78%
rename from tests/robotests/src/com/android/settings/users/TimeoutToUserZeroSettingsTest.java
rename to tests/robotests/src/com/android/settings/users/TimeoutToDockUserSettingsTest.java
index 0bd5b60117077abf7e8a37190e1c71e354be3112..6c95fce73f2ea3171cda3c4c9eff6c931ba11f7a 100644
--- a/tests/robotests/src/com/android/settings/users/TimeoutToUserZeroSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/users/TimeoutToDockUserSettingsTest.java
@@ -42,11 +42,11 @@ import java.util.List;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {ShadowFragment.class})
-public class TimeoutToUserZeroSettingsTest {
+public class TimeoutToDockUserSettingsTest {
@Mock
private FragmentActivity mActivity;
- private TimeoutToUserZeroSettings mSettings;
+ private TimeoutToDockUserSettings mSettings;
private String[] mEntries;
private String[] mValues;
@@ -57,10 +57,10 @@ public class TimeoutToUserZeroSettingsTest {
final Context context = spy(ApplicationProvider.getApplicationContext());
mEntries = context.getResources().getStringArray(
- R.array.switch_to_user_zero_when_docked_timeout_entries);
+ R.array.switch_to_dock_user_when_docked_timeout_entries);
mValues = context.getResources().getStringArray(
- R.array.switch_to_user_zero_when_docked_timeout_values);
- mSettings = spy(new TimeoutToUserZeroSettings());
+ R.array.switch_to_dock_user_when_docked_timeout_values);
+ mSettings = spy(new TimeoutToDockUserSettings());
doReturn(context).when(mSettings).getContext();
doReturn(mActivity).when(mSettings).getActivity();
@@ -78,8 +78,9 @@ public class TimeoutToUserZeroSettingsTest {
}
@Test
- public void defaultKey_settingNotSet_shouldReturnFirstValueAsDefault() {
- assertThat(mSettings.getDefaultKey()).isEqualTo(mValues[0]);
+ public void defaultKey_settingNotSet_shouldReturnSecondValueAsDefault() {
+ assertThat(mSettings.getDefaultKey()).isEqualTo(
+ mValues[TimeoutToDockUserSettings.DEFAULT_TIMEOUT_SETTING_VALUE_INDEX]);
}
@Test
@@ -95,4 +96,11 @@ public class TimeoutToUserZeroSettingsTest {
mSettings.setDefaultKey(expectedKey);
assertThat(mSettings.getDefaultKey()).isEqualTo(expectedKey);
}
+
+ @Test
+ public void defaultKey_setToThirdValue_shouldSaveToSettings() {
+ final String expectedKey = mValues[2];
+ mSettings.setDefaultKey(expectedKey);
+ assertThat(mSettings.getDefaultKey()).isEqualTo(expectedKey);
+ }
}
diff --git a/tests/robotests/src/com/android/settings/wifi/NetworkRequestDialogFragmentTest.java b/tests/robotests/src/com/android/settings/wifi/NetworkRequestDialogFragmentTest.java
index 66d399c81928b647fe1b59ce9756f803afa1750a..e5b13c4b114a90330cc0c05b7482ddae4270c61b 100644
--- a/tests/robotests/src/com/android/settings/wifi/NetworkRequestDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/NetworkRequestDialogFragmentTest.java
@@ -16,6 +16,9 @@
package com.android.settings.wifi;
+import static com.android.wifitrackerlib.WifiEntry.SECURITY_PSK;
+import static com.android.wifitrackerlib.WifiEntry.SECURITY_SAE;
+
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
@@ -46,16 +49,20 @@ import com.android.wifitrackerlib.WifiEntry;
import com.android.wifitrackerlib.WifiPickerTracker;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InOrder;
-import org.mockito.MockitoAnnotations;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
@RunWith(RobolectricTestRunner.class)
@@ -63,15 +70,34 @@ import java.util.List;
public class NetworkRequestDialogFragmentTest {
private static final String KEY_SSID = "key_ssid";
- private static final String KEY_SECURITY = "key_security";
+ private static final String TEST_CAPABILITIES_OPEN = "[ESS]";
+ private static final String TEST_CAPABILITIES_WPA2_PSK = "[WPA2-PSK-CCMP][ESS]";
+ private static final String TEST_CAPABILITIES_WPA3_SAE = "[RSN-PSK+SAE-CCMP][ESS]";
private static final String TEST_APP_NAME = "TestAppName";
+ @Rule
+ public final MockitoRule mMockitoRule = MockitoJUnit.rule();
+ @Mock
+ WifiPickerTracker mWifiPickerTracker;
+ @Mock
+ WifiEntry mWifiEntry;
+
private FragmentActivity mActivity;
private NetworkRequestDialogFragment networkRequestDialogFragment;
+ ScanResult mScanResult = new ScanResult();
+
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
+ when(mWifiEntry.getSsid()).thenReturn(KEY_SSID);
+ when(mWifiEntry.getSecurityTypes()).thenReturn(Arrays.asList(SECURITY_PSK, SECURITY_SAE));
+ when(mWifiEntry.getSecurity()).thenReturn(SECURITY_PSK);
+ when(mWifiPickerTracker.getConnectedWifiEntry()).thenReturn(null);
+ when(mWifiPickerTracker.getWifiEntries()).thenReturn(Arrays.asList(mWifiEntry));
+
+ mScanResult.SSID = KEY_SSID;
+ mScanResult.capabilities = TEST_CAPABILITIES_OPEN;
+
FakeFeatureFactory fakeFeatureFactory = FakeFeatureFactory.setupForTest();
when(fakeFeatureFactory.wifiTrackerLibProvider.createWifiPickerTracker(
any(), any(), any(), any(), any(), anyLong(), anyLong(), any()))
@@ -81,7 +107,7 @@ public class NetworkRequestDialogFragmentTest {
new Intent().putExtra(NetworkRequestDialogFragment.EXTRA_APP_NAME,
TEST_APP_NAME)).setup().get();
networkRequestDialogFragment = spy(NetworkRequestDialogFragment.newInstance());
- networkRequestDialogFragment.mWifiPickerTracker = mock(WifiPickerTracker.class);
+ networkRequestDialogFragment.mWifiPickerTracker = mWifiPickerTracker;
}
@Test
@@ -147,12 +173,10 @@ public class NetworkRequestDialogFragmentTest {
@Test
public void onWifiStateChanged_nonEmptyMatchedScanResults_shouldUpdateWifiEntries() {
final InOrder inOrder = inOrder(networkRequestDialogFragment);
+ mScanResult.capabilities = TEST_CAPABILITIES_OPEN;
+ networkRequestDialogFragment.onMatch(Arrays.asList(mScanResult));
- final List scanResults = new ArrayList<>();
- networkRequestDialogFragment.mMatchedScanResults = scanResults;
- ScanResult scanResult = mock(ScanResult.class);
- networkRequestDialogFragment.mMatchedScanResults.add(scanResult);
- networkRequestDialogFragment.onMatch(scanResults);
+ networkRequestDialogFragment.onWifiStateChanged();
inOrder.verify(networkRequestDialogFragment).updateWifiEntries();
inOrder.verify(networkRequestDialogFragment).updateUi();
@@ -161,12 +185,10 @@ public class NetworkRequestDialogFragmentTest {
@Test
public void onWifiEntriesChanged_nonEmptyMatchedScanResults_shouldUpdateWifiEntries() {
final InOrder inOrder = inOrder(networkRequestDialogFragment);
+ mScanResult.capabilities = TEST_CAPABILITIES_OPEN;
+ networkRequestDialogFragment.onMatch(Arrays.asList(mScanResult));
- final List scanResults = new ArrayList<>();
- networkRequestDialogFragment.mMatchedScanResults = scanResults;
- ScanResult scanResult = mock(ScanResult.class);
- networkRequestDialogFragment.mMatchedScanResults.add(scanResult);
- networkRequestDialogFragment.onMatch(scanResults);
+ networkRequestDialogFragment.onWifiEntriesChanged();
inOrder.verify(networkRequestDialogFragment).updateWifiEntries();
inOrder.verify(networkRequestDialogFragment).updateUi();
@@ -280,4 +302,34 @@ public class NetworkRequestDialogFragmentTest {
// Check
verify(selectionCallback, times(1)).reject();
}
+
+ @Test
+ public void updateWifiEntries_noMatchSecurityWifi_filteredWifiIsEmpty() {
+ mScanResult.capabilities = TEST_CAPABILITIES_OPEN;
+ networkRequestDialogFragment.onMatch(Arrays.asList(mScanResult));
+
+ networkRequestDialogFragment.updateWifiEntries();
+
+ assertThat(networkRequestDialogFragment.mFilteredWifiEntries.size()).isEqualTo(0);
+ }
+
+ @Test
+ public void updateWifiEntries_matchWpa2Wifi_filteredWifiNotEmpty() {
+ mScanResult.capabilities = TEST_CAPABILITIES_WPA2_PSK;
+ networkRequestDialogFragment.onMatch(Arrays.asList(mScanResult));
+
+ networkRequestDialogFragment.updateWifiEntries();
+
+ assertThat(networkRequestDialogFragment.mFilteredWifiEntries.size()).isNotEqualTo(0);
+ }
+
+ @Test
+ public void updateWifiEntries_matchWpa3Wifi_filteredWifiNotEmpty() {
+ mScanResult.capabilities = TEST_CAPABILITIES_WPA3_SAE;
+ networkRequestDialogFragment.onMatch(Arrays.asList(mScanResult));
+
+ networkRequestDialogFragment.updateWifiEntries();
+
+ assertThat(networkRequestDialogFragment.mFilteredWifiEntries.size()).isNotEqualTo(0);
+ }
}
diff --git a/tests/robotests/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivityTest.java b/tests/robotests/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivityTest.java
index d8605ded82932e3c7ccdde0430e9098f83a48957..88fa83afbf76b10f30eeb087da718f4819f2230a 100644
--- a/tests/robotests/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivityTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivityTest.java
@@ -16,6 +16,10 @@
package com.android.settings.wifi.dpp;
+import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
+
+import static com.google.common.truth.Truth.assertThat;
+
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
@@ -72,6 +76,12 @@ public class WifiDppConfiguratorActivityTest {
Robolectric.setupActivity(WifiDppConfiguratorActivity.class);
}
+ @Test
+ public void launchActivity_shouldAddFlagSecure() {
+ assertThat(mActivity.getWindow().getAttributes().flags & FLAG_SECURE)
+ .isEqualTo(FLAG_SECURE);
+ }
+
@Test
public void handleIntent_isGuestUser_shouldFinish() {
when(mUserManager.isGuestUser()).thenReturn(true);
diff --git a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java
index e8ee7c3b90e77208b610b926ba4bf2bdd84b0467..bc6053b428db243746794ea0971ebefe3eb0f112 100644
--- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java
@@ -16,13 +16,14 @@
package com.android.settings.wifi.tether;
+import static com.android.settings.wifi.WifiUtils.setCanShowWifiHotspotCached;
+
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;
import android.content.Context;
-import android.net.TetheringManager;
import android.net.wifi.SoftApConfiguration;
import android.net.wifi.WifiManager;
@@ -62,8 +63,6 @@ public class WifiTetherPreferenceControllerTest {
@Mock
private Lifecycle mLifecycle;
@Mock
- private TetheringManager mTetheringManager;
- @Mock
private WifiManager mWifiManager;
@Mock
private PreferenceScreen mScreen;
@@ -74,38 +73,37 @@ public class WifiTetherPreferenceControllerTest {
@Before
public void setUp() {
+ setCanShowWifiHotspotCached(true);
FakeFeatureFactory.setupForTest();
mPreference = new PrimarySwitchPreference(mContext);
- when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
mSoftApConfiguration = new SoftApConfiguration.Builder().setSsid(SSID).build();
when(mWifiManager.getSoftApConfiguration()).thenReturn(mSoftApConfiguration);
- when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"});
mController = new WifiTetherPreferenceController(mContext, mLifecycle, mWifiManager,
- mTetheringManager, false /* initSoftApManager */, true /* isWifiTetheringAllow */);
+ false /* initSoftApManager */, true /* isWifiTetheringAllow */);
mController.displayPreference(mScreen);
}
@Test
- public void isAvailable_noTetherRegex_shouldReturnFalse() {
- when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{});
- mController = new WifiTetherPreferenceController(mContext, mLifecycle, mWifiManager,
- mTetheringManager, false /* initSoftApManager */, true /* isWifiTetheringAllow */);
+ public void isAvailable_canNotShowWifiHotspot_shouldReturnFalse() {
+ setCanShowWifiHotspotCached(false);
assertThat(mController.isAvailable()).isFalse();
}
@Test
- public void isAvailable_hasTetherRegex_shouldReturnTrue() {
+ public void isAvailable_canShowWifiHostspot_shouldReturnTrue() {
+ setCanShowWifiHotspotCached(true);
+
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void displayPreference_wifiTetheringNotAllowed_shouldDisable() {
mController = new WifiTetherPreferenceController(mContext, mLifecycle, mWifiManager,
- mTetheringManager, false /* initSoftApManager */, false /* isWifiTetheringAllow */);
+ false /* initSoftApManager */, false /* isWifiTetheringAllow */);
mController.displayPreference(mScreen);
@@ -116,7 +114,7 @@ public class WifiTetherPreferenceControllerTest {
@Test
public void displayPreference_wifiTetheringAllowed_shouldEnable() {
mController = new WifiTetherPreferenceController(mContext, mLifecycle, mWifiManager,
- mTetheringManager, false /* initSoftApManager */, true /* isWifiTetheringAllow */);
+ false /* initSoftApManager */, true /* isWifiTetheringAllow */);
mController.displayPreference(mScreen);
diff --git a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java
index d19bc909555812319ed9fcbc37c92843d9e08592..7f8a06d1521b8829223e08bf384b12ac6a6c5274 100644
--- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java
@@ -16,6 +16,8 @@
package com.android.settings.wifi.tether;
+import static com.android.settings.wifi.WifiUtils.setCanShowWifiHotspotCached;
+
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
@@ -35,6 +37,7 @@ import android.net.TetheringManager;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.UserManager;
+import android.util.FeatureFlagUtils;
import android.widget.TextView;
import androidx.fragment.app.FragmentActivity;
@@ -42,6 +45,8 @@ import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.R;
+import com.android.settings.core.FeatureFlags;
+import com.android.settings.dashboard.RestrictedDashboardFragment;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.shadow.ShadowFragment;
@@ -55,6 +60,8 @@ import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
+import org.robolectric.annotation.Implementation;
+import org.robolectric.annotation.Implements;
import org.robolectric.util.ReflectionHelpers;
import java.util.List;
@@ -88,6 +95,8 @@ public class WifiTetherSettingsTest {
@Before
public void setUp() {
+ FeatureFlagUtils.setEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE, false);
+ setCanShowWifiHotspotCached(true);
doReturn(mWifiManager).when(mContext).getSystemService(WifiManager.class);
doReturn(mConnectivityManager)
.when(mContext).getSystemService(Context.CONNECTIVITY_SERVICE);
@@ -100,6 +109,17 @@ public class WifiTetherSettingsTest {
mWifiTetherSettings = new WifiTetherSettings(mWifiRestriction);
}
+ @Test
+ @Config(shadows = ShadowRestrictedDashboardFragment.class)
+ public void onCreate_canNotShowWifiHotspot_shouldFinish() {
+ setCanShowWifiHotspotCached(false);
+ mWifiTetherSettings = spy(new WifiTetherSettings(mWifiRestriction));
+
+ mWifiTetherSettings.onCreate(null);
+
+ verify(mWifiTetherSettings).finish();
+ }
+
@Test
@Config(shadows = ShadowFragment.class)
public void onStart_uiIsRestricted_removeAllPreferences() {
@@ -201,6 +221,22 @@ public class WifiTetherSettingsTest {
assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_TETHER_MAXIMIZE_COMPATIBILITY);
}
+ @Test
+ public void isPageSearchEnabled_canShowWifiHotspot_returnTrue() {
+ setCanShowWifiHotspotCached(true);
+
+ assertThat(WifiTetherSettings.SEARCH_INDEX_DATA_PROVIDER.isPageSearchEnabled(mContext))
+ .isTrue();
+ }
+
+ @Test
+ public void isPageSearchEnabled_canNotShowWifiHotspot_returnFalse() {
+ setCanShowWifiHotspotCached(false);
+
+ assertThat(WifiTetherSettings.SEARCH_INDEX_DATA_PROVIDER.isPageSearchEnabled(mContext))
+ .isFalse();
+ }
+
private void spyWifiTetherSettings() {
mWifiTetherSettings = spy(new WifiTetherSettings(mWifiRestriction));
final FragmentActivity activity = mock(FragmentActivity.class);
@@ -219,4 +255,13 @@ public class WifiTetherSettingsTest {
mWifiTetherSettings.onCreate(Bundle.EMPTY);
}
+
+ @Implements(RestrictedDashboardFragment.class)
+ public static final class ShadowRestrictedDashboardFragment {
+
+ @Implementation
+ public void onCreate(Bundle icicle) {
+ // do nothing
+ }
+ }
}
diff --git a/tests/unit/src/com/android/settings/development/transcode/TranscodeDefaultOptionPreferenceControllerTest.java b/tests/unit/src/com/android/settings/development/transcode/TranscodeDefaultOptionPreferenceControllerTest.java
index e3fa0766acc371cc62fccf0f53fc65ae1504d4e6..ecbae2d2c74d495f8125f36d76efa8bbc1fe4107 100644
--- a/tests/unit/src/com/android/settings/development/transcode/TranscodeDefaultOptionPreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/development/transcode/TranscodeDefaultOptionPreferenceControllerTest.java
@@ -20,6 +20,7 @@ import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.os.SystemProperties;
+import android.provider.Settings;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -36,11 +37,14 @@ public class TranscodeDefaultOptionPreferenceControllerTest {
"persist.sys.fuse.transcode_default";
private TranscodeDefaultOptionPreferenceController mUnderTest;
+ private Context mContext;
@Before
public void setUp() {
- Context context = ApplicationProvider.getApplicationContext();
- mUnderTest = new TranscodeDefaultOptionPreferenceController(context, "some_key");
+ mContext = ApplicationProvider.getApplicationContext();
+ mUnderTest = new TranscodeDefaultOptionPreferenceController(mContext, "some_key");
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
}
@Test
@@ -74,4 +78,12 @@ public class TranscodeDefaultOptionPreferenceControllerTest {
assertThat(mUnderTest.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.AVAILABLE);
}
+
+ @Test
+ public void getAvailabilityStatus_developerOptionFalse_shouldReturnUNAVAILABLE() {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
+ assertThat(mUnderTest.getAvailabilityStatus()).isEqualTo(
+ BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
+ }
}
diff --git a/tests/unit/src/com/android/settings/development/transcode/TranscodeDisableCachePreferenceControllerTest.java b/tests/unit/src/com/android/settings/development/transcode/TranscodeDisableCachePreferenceControllerTest.java
index d1a3355e36af699ae1ab2d7662ec1f637bcb9fa1..e7d1d4b1af2584bab4a98e246a14024b8a6246a4 100644
--- a/tests/unit/src/com/android/settings/development/transcode/TranscodeDisableCachePreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/development/transcode/TranscodeDisableCachePreferenceControllerTest.java
@@ -22,6 +22,7 @@ import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.os.SystemProperties;
+import android.provider.Settings;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -36,11 +37,14 @@ import org.junit.runner.RunWith;
public class TranscodeDisableCachePreferenceControllerTest {
private TranscodeDisableCachePreferenceController mUnderTest;
+ private Context mContext;
@Before
public void setUp() {
- Context context = ApplicationProvider.getApplicationContext();
- mUnderTest = new TranscodeDisableCachePreferenceController(context, "some_key");
+ mContext = ApplicationProvider.getApplicationContext();
+ mUnderTest = new TranscodeDisableCachePreferenceController(mContext, "some_key");
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
}
@Test
@@ -74,4 +78,12 @@ public class TranscodeDisableCachePreferenceControllerTest {
assertThat(mUnderTest.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.AVAILABLE);
}
+
+ @Test
+ public void getAvailabilityStatus_developerOptionFalse_shouldReturnUNAVAILABLE() {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
+ assertThat(mUnderTest.getAvailabilityStatus()).isEqualTo(
+ BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
+ }
}
diff --git a/tests/unit/src/com/android/settings/development/transcode/TranscodeGlobalTogglePreferenceControllerTest.java b/tests/unit/src/com/android/settings/development/transcode/TranscodeGlobalTogglePreferenceControllerTest.java
index 7c0acd7bea660da68f5199bd65e48aba1cf9f083..0751fd9b21194791cd684e465be38fd601786d85 100644
--- a/tests/unit/src/com/android/settings/development/transcode/TranscodeGlobalTogglePreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/development/transcode/TranscodeGlobalTogglePreferenceControllerTest.java
@@ -20,10 +20,13 @@ import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.os.SystemProperties;
+import android.provider.Settings;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
+import com.android.settings.core.BasePreferenceController;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -34,11 +37,14 @@ public class TranscodeGlobalTogglePreferenceControllerTest {
private static final String TRANSCODE_ENABLED_PROP_KEY = "persist.sys.fuse.transcode_enabled";
private TranscodeGlobalTogglePreferenceController mController;
+ private Context mContext;
@Before
public void setUp() {
- Context context = ApplicationProvider.getApplicationContext();
- mController = new TranscodeGlobalTogglePreferenceController(context, "test_key");
+ mContext = ApplicationProvider.getApplicationContext();
+ mController = new TranscodeGlobalTogglePreferenceController(mContext, "test_key");
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
}
@Test
@@ -75,4 +81,12 @@ public class TranscodeGlobalTogglePreferenceControllerTest {
// Verify the system property was updated.
assertThat(SystemProperties.getBoolean(TRANSCODE_ENABLED_PROP_KEY, true)).isFalse();
}
+
+ @Test
+ public void getAvailabilityStatus_developerOptionFalse_shouldReturnUNAVAILABLE() {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(
+ BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
+ }
}
diff --git a/tests/unit/src/com/android/settings/development/transcode/TranscodeNotificationPreferenceControllerTest.java b/tests/unit/src/com/android/settings/development/transcode/TranscodeNotificationPreferenceControllerTest.java
index 65bfbf571e2c1a68b01269904c2cdac5b475a361..d9ae0a48c5b1f23f4709264d09829a17d9dc4bc1 100644
--- a/tests/unit/src/com/android/settings/development/transcode/TranscodeNotificationPreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/development/transcode/TranscodeNotificationPreferenceControllerTest.java
@@ -22,6 +22,7 @@ import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.os.SystemProperties;
+import android.provider.Settings;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -36,10 +37,14 @@ import org.junit.runner.RunWith;
public class TranscodeNotificationPreferenceControllerTest {
private TranscodeNotificationPreferenceController mUnderTest;
+ private Context mContext;
+
@Before
public void setUp() {
- Context context = ApplicationProvider.getApplicationContext();
- mUnderTest = new TranscodeNotificationPreferenceController(context, "notification_key");
+ mContext = ApplicationProvider.getApplicationContext();
+ mUnderTest = new TranscodeNotificationPreferenceController(mContext, "notification_key");
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
}
@Test
@@ -73,4 +78,12 @@ public class TranscodeNotificationPreferenceControllerTest {
assertThat(mUnderTest.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.AVAILABLE);
}
+
+ @Test
+ public void getAvailabilityStatus_developerOptionFalse_shouldReturnUNAVAILABLE() {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
+ assertThat(mUnderTest.getAvailabilityStatus()).isEqualTo(
+ BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
+ }
}
diff --git a/tests/unit/src/com/android/settings/development/transcode/TranscodeUserControlPreferenceControllerTest.java b/tests/unit/src/com/android/settings/development/transcode/TranscodeUserControlPreferenceControllerTest.java
index 63a6ac6cb22f66628ff6af5ddff5aa34ad06c338..6e4bfc834fb8415e378af52bf0805a1af49d765c 100644
--- a/tests/unit/src/com/android/settings/development/transcode/TranscodeUserControlPreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/development/transcode/TranscodeUserControlPreferenceControllerTest.java
@@ -20,6 +20,7 @@ import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.os.SystemProperties;
+import android.provider.Settings;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -36,11 +37,14 @@ public class TranscodeUserControlPreferenceControllerTest {
"persist.sys.fuse.transcode_user_control";
private TranscodeUserControlPreferenceController mUnderTest;
+ private Context mContext;
@Before
public void setUp() {
- Context context = ApplicationProvider.getApplicationContext();
- mUnderTest = new TranscodeUserControlPreferenceController(context, "some_key");
+ mContext = ApplicationProvider.getApplicationContext();
+ mUnderTest = new TranscodeUserControlPreferenceController(mContext, "some_key");
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
}
@Test
@@ -74,4 +78,12 @@ public class TranscodeUserControlPreferenceControllerTest {
assertThat(mUnderTest.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.AVAILABLE);
}
+
+ @Test
+ public void getAvailabilityStatus_developerOptionFalse_shouldReturnUNAVAILABLE() {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
+ assertThat(mUnderTest.getAvailabilityStatus()).isEqualTo(
+ BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
+ }
}
diff --git a/tests/unit/src/com/android/settings/display/ScreenSaverPreferenceControllerTest.java b/tests/unit/src/com/android/settings/display/ScreenSaverPreferenceControllerTest.java
index 3319e2a710d3a995cecc8695e97ade704196dc9d..180ea90925fc709bcb6a21651a323f5e3f669b48 100644
--- a/tests/unit/src/com/android/settings/display/ScreenSaverPreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/display/ScreenSaverPreferenceControllerTest.java
@@ -45,11 +45,13 @@ public class ScreenSaverPreferenceControllerTest {
private ScreenSaverPreferenceController mController;
+ private final String mPrefKey = "test_screensaver";
+
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
- mController = new ScreenSaverPreferenceController(mContext);
+ mController = new ScreenSaverPreferenceController(mContext, mPrefKey);
when(mContext.getResources()).thenReturn(mResources);
when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
@@ -60,7 +62,7 @@ public class ScreenSaverPreferenceControllerTest {
when(mResources.getBoolean(
com.android.internal.R.bool.config_dreamsSupported)).thenReturn(true);
when(mResources.getBoolean(
- com.android.internal.R.bool.config_dreamsOnlyEnabledForSystemUser))
+ com.android.internal.R.bool.config_dreamsOnlyEnabledForDockUser))
.thenReturn(false);
when(mUserManager.isSystemUser()).thenReturn(true);
assertTrue(mController.isAvailable());
@@ -71,7 +73,7 @@ public class ScreenSaverPreferenceControllerTest {
when(mResources.getBoolean(
com.android.internal.R.bool.config_dreamsSupported)).thenReturn(true);
when(mResources.getBoolean(
- com.android.internal.R.bool.config_dreamsOnlyEnabledForSystemUser))
+ com.android.internal.R.bool.config_dreamsOnlyEnabledForDockUser))
.thenReturn(false);
when(mUserManager.isSystemUser()).thenReturn(false);
assertTrue(mController.isAvailable());
@@ -82,7 +84,7 @@ public class ScreenSaverPreferenceControllerTest {
when(mResources.getBoolean(
com.android.internal.R.bool.config_dreamsSupported)).thenReturn(false);
when(mResources.getBoolean(
- com.android.internal.R.bool.config_dreamsOnlyEnabledForSystemUser))
+ com.android.internal.R.bool.config_dreamsOnlyEnabledForDockUser))
.thenReturn(false);
when(mUserManager.isSystemUser()).thenReturn(true);
assertFalse(mController.isAvailable());
@@ -93,7 +95,7 @@ public class ScreenSaverPreferenceControllerTest {
when(mResources.getBoolean(
com.android.internal.R.bool.config_dreamsSupported)).thenReturn(true);
when(mResources.getBoolean(
- com.android.internal.R.bool.config_dreamsOnlyEnabledForSystemUser))
+ com.android.internal.R.bool.config_dreamsOnlyEnabledForDockUser))
.thenReturn(true);
when(mUserManager.isSystemUser()).thenReturn(true);
assertTrue(mController.isAvailable());
@@ -104,7 +106,7 @@ public class ScreenSaverPreferenceControllerTest {
when(mResources.getBoolean(
com.android.internal.R.bool.config_dreamsSupported)).thenReturn(true);
when(mResources.getBoolean(
- com.android.internal.R.bool.config_dreamsOnlyEnabledForSystemUser))
+ com.android.internal.R.bool.config_dreamsOnlyEnabledForDockUser))
.thenReturn(true);
when(mUserManager.isSystemUser()).thenReturn(false);
assertFalse(mController.isAvailable());
diff --git a/tests/unit/src/com/android/settings/network/InternetResetHelperTest.java b/tests/unit/src/com/android/settings/network/InternetResetHelperTest.java
index e6df8a0645109b8bb22b879f1378cab119f24230..3fe688273d85e7b2e1044806fa252810f72c8869 100644
--- a/tests/unit/src/com/android/settings/network/InternetResetHelperTest.java
+++ b/tests/unit/src/com/android/settings/network/InternetResetHelperTest.java
@@ -16,6 +16,8 @@
package com.android.settings.network;
+import static com.android.settings.network.InternetResetHelper.RESTART_TIMEOUT_MS;
+
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
@@ -29,8 +31,6 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.IntentFilter;
import android.net.wifi.WifiManager;
-import android.os.Handler;
-import android.os.HandlerThread;
import android.os.Looper;
import androidx.lifecycle.Lifecycle;
@@ -39,7 +39,6 @@ import androidx.preference.PreferenceCategory;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
-import com.android.settingslib.connectivity.ConnectivitySubsystemsRecoveryManager;
import com.android.settingslib.utils.HandlerInjector;
import org.junit.Before;
@@ -47,6 +46,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
+import org.mockito.Spy;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
@@ -55,66 +55,46 @@ public class InternetResetHelperTest {
@Rule
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
+ @Spy
+ private final Context mContext = ApplicationProvider.getApplicationContext();
@Mock
private WifiManager mWifiManager;
@Mock
- public HandlerThread mWorkerThread;
+ InternetResetHelper.RecoveryWorker mRecoveryWorker;
@Mock
- public ConnectivitySubsystemsRecoveryManager mConnectivitySubsystemsRecoveryManager;
+ HandlerInjector mHandlerInjector;
@Mock
public NetworkMobileProviderController mMobileNetworkController;
- private Context mContext;
private InternetResetHelper mInternetResetHelper;
private Preference mResettingPreference;
private Preference mWifiTogglePreferences;
private PreferenceCategory mConnectedWifiEntryPreferences;
+ private PreferenceCategory mFirstWifiEntryPreference;
private PreferenceCategory mWifiEntryPreferences;
- private FakeHandlerInjector mFakeHandlerInjector;
-
- private static class FakeHandlerInjector extends HandlerInjector {
-
- private Runnable mRunnable;
-
- FakeHandlerInjector(Handler handler) {
- super(handler);
- }
-
- @Override
- public void postDelayed(Runnable runnable, long delayMillis) {
- mRunnable = runnable;
- }
-
- public Runnable getRunnable() {
- return mRunnable;
- }
- }
-
@Before
public void setUp() {
- mContext = spy(ApplicationProvider.getApplicationContext());
when(mContext.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
+ when(mRecoveryWorker.isRecovering()).thenReturn(false);
if (Looper.myLooper() == null) {
Looper.prepare();
}
- mResettingPreference = new Preference(mContext);
+ mResettingPreference = spy(new Preference(mContext));
mWifiTogglePreferences = new Preference(mContext);
mConnectedWifiEntryPreferences = spy(new PreferenceCategory(mContext));
+ mFirstWifiEntryPreference = spy(new PreferenceCategory(mContext));
mWifiEntryPreferences = spy(new PreferenceCategory(mContext));
- final Lifecycle lifecycle = mock(Lifecycle.class);
- mInternetResetHelper = new InternetResetHelper(mContext, lifecycle);
- mInternetResetHelper.mWorkerThread = mWorkerThread;
- mFakeHandlerInjector = new FakeHandlerInjector(mContext.getMainThreadHandler());
- mInternetResetHelper.mHandlerInjector = mFakeHandlerInjector;
- mInternetResetHelper.mConnectivitySubsystemsRecoveryManager =
- mConnectivitySubsystemsRecoveryManager;
- mInternetResetHelper.setResettingPreference(mResettingPreference);
- mInternetResetHelper.setMobileNetworkController(mMobileNetworkController);
- mInternetResetHelper.setWifiTogglePreference(mWifiTogglePreferences);
- mInternetResetHelper.addWifiNetworkPreference(mConnectedWifiEntryPreferences);
- mInternetResetHelper.addWifiNetworkPreference(mWifiEntryPreferences);
+ mInternetResetHelper = new InternetResetHelper(mContext, mock(Lifecycle.class),
+ mMobileNetworkController,
+ mWifiTogglePreferences,
+ mConnectedWifiEntryPreferences,
+ mFirstWifiEntryPreference,
+ mWifiEntryPreferences,
+ mResettingPreference);
+ mInternetResetHelper.mHandlerInjector = mHandlerInjector;
+ mInternetResetHelper.mRecoveryWorker = mRecoveryWorker;
}
@Test
@@ -135,30 +115,10 @@ public class InternetResetHelperTest {
}
@Test
- public void onDestroy_quitWorkerThread() {
+ public void onDestroy_removeCallbacks() {
mInternetResetHelper.onDestroy();
- verify(mWorkerThread).quit();
- }
-
- @Test
- public void onSubsystemRestartOperationEnd_recoveryIsNotReady_postResumeRunnable() {
- mInternetResetHelper.mIsRecoveryReady = false;
-
- mInternetResetHelper.onSubsystemRestartOperationEnd();
-
- assertThat(mInternetResetHelper.mIsRecoveryReady).isTrue();
- assertThat(mFakeHandlerInjector.getRunnable())
- .isEqualTo(mInternetResetHelper.mResumeRunnable);
- }
-
- @Test
- public void onSubsystemRestartOperationEnd_recoveryIsReady_doNothing() {
- mInternetResetHelper.mIsRecoveryReady = true;
-
- mInternetResetHelper.onSubsystemRestartOperationEnd();
-
- assertThat(mFakeHandlerInjector.getRunnable()).isNull();
+ verify(mHandlerInjector).removeCallbacks(any());
}
@Test
@@ -169,19 +129,16 @@ public class InternetResetHelperTest {
mInternetResetHelper.updateWifiStateChange();
assertThat(mInternetResetHelper.mIsWifiReady).isFalse();
- assertThat(mFakeHandlerInjector.getRunnable()).isNull();
}
@Test
- public void updateWifiStateChange_wifiIsNotReadyAndWifiEnabled_postResumeRunnable() {
+ public void updateWifiStateChange_wifiIsNotReadyAndWifiEnabled_updateWifiIsReady() {
mInternetResetHelper.mIsWifiReady = false;
when(mWifiManager.isWifiEnabled()).thenReturn(true);
mInternetResetHelper.updateWifiStateChange();
assertThat(mInternetResetHelper.mIsWifiReady).isTrue();
- assertThat(mFakeHandlerInjector.getRunnable())
- .isEqualTo(mInternetResetHelper.mResumeRunnable);
}
@Test
@@ -191,7 +148,6 @@ public class InternetResetHelperTest {
mInternetResetHelper.updateWifiStateChange();
assertThat(mInternetResetHelper.mIsWifiReady).isTrue();
- assertThat(mFakeHandlerInjector.getRunnable()).isNull();
}
@Test
@@ -203,16 +159,15 @@ public class InternetResetHelperTest {
// Hide subsystem preferences
verify(mMobileNetworkController).hidePreference(true /* hide */, true /* immediately*/);
assertThat(mWifiTogglePreferences.isVisible()).isFalse();
- verify(mConnectedWifiEntryPreferences).removeAll();
assertThat(mConnectedWifiEntryPreferences.isVisible()).isFalse();
- verify(mWifiEntryPreferences).removeAll();
+ assertThat(mFirstWifiEntryPreference.isVisible()).isFalse();
assertThat(mWifiEntryPreferences.isVisible()).isFalse();
}
@Test
public void resumePreferences_onlyRecoveryReady_shouldShowSubSysHideResetting() {
mInternetResetHelper.suspendPreferences();
- mInternetResetHelper.mIsRecoveryReady = true;
+ when(mRecoveryWorker.isRecovering()).thenReturn(false);
mInternetResetHelper.mIsWifiReady = false;
mInternetResetHelper.resumePreferences();
@@ -224,13 +179,14 @@ public class InternetResetHelperTest {
// Hide Wi-Fi preferences
assertThat(mWifiTogglePreferences.isVisible()).isFalse();
assertThat(mConnectedWifiEntryPreferences.isVisible()).isFalse();
+ assertThat(mFirstWifiEntryPreference.isVisible()).isFalse();
assertThat(mWifiEntryPreferences.isVisible()).isFalse();
}
@Test
public void resumePreferences_onlyWifiReady_shouldShowSubSysHideResetting() {
mInternetResetHelper.suspendPreferences();
- mInternetResetHelper.mIsRecoveryReady = false;
+ when(mRecoveryWorker.isRecovering()).thenReturn(true);
mInternetResetHelper.mIsWifiReady = true;
mInternetResetHelper.resumePreferences();
@@ -240,6 +196,7 @@ public class InternetResetHelperTest {
// Show Wi-Fi preferences
assertThat(mWifiTogglePreferences.isVisible()).isTrue();
assertThat(mConnectedWifiEntryPreferences.isVisible()).isTrue();
+ assertThat(mFirstWifiEntryPreference.isVisible()).isTrue();
assertThat(mWifiEntryPreferences.isVisible()).isTrue();
// Hide Mobile Network controller
verify(mMobileNetworkController, never())
@@ -249,14 +206,16 @@ public class InternetResetHelperTest {
@Test
public void resumePreferences_allReady_shouldShowSubSysHideResetting() {
mInternetResetHelper.suspendPreferences();
- mInternetResetHelper.mIsRecoveryReady = true;
+ when(mRecoveryWorker.isRecovering()).thenReturn(false);
mInternetResetHelper.mIsWifiReady = true;
+
mInternetResetHelper.resumePreferences();
// Show subsystem preferences
verify(mMobileNetworkController).hidePreference(false, true);
assertThat(mWifiTogglePreferences.isVisible()).isTrue();
assertThat(mConnectedWifiEntryPreferences.isVisible()).isTrue();
+ assertThat(mFirstWifiEntryPreference.isVisible()).isTrue();
assertThat(mWifiEntryPreferences.isVisible()).isTrue();
// Hide resetting preference
assertThat(mResettingPreference.isVisible()).isFalse();
@@ -264,22 +223,39 @@ public class InternetResetHelperTest {
@Test
public void restart_recoveryNotAvailable_shouldDoTriggerSubsystemRestart() {
- when(mConnectivitySubsystemsRecoveryManager.isRecoveryAvailable()).thenReturn(false);
+ when(mRecoveryWorker.isRecoveryAvailable()).thenReturn(false);
mInternetResetHelper.restart();
- verify(mConnectivitySubsystemsRecoveryManager, never())
- .triggerSubsystemRestart(any(), any());
+ verify(mRecoveryWorker, never()).triggerRestart();
}
@Test
public void restart_recoveryAvailable_triggerSubsystemRestart() {
- when(mConnectivitySubsystemsRecoveryManager.isRecoveryAvailable()).thenReturn(true);
+ when(mRecoveryWorker.isRecoveryAvailable()).thenReturn(true);
mInternetResetHelper.restart();
- assertThat(mFakeHandlerInjector.getRunnable())
- .isEqualTo(mInternetResetHelper.mTimeoutRunnable);
- verify(mConnectivitySubsystemsRecoveryManager).triggerSubsystemRestart(any(), any());
+ verify(mHandlerInjector)
+ .postDelayed(mInternetResetHelper.mTimeoutRunnable, RESTART_TIMEOUT_MS);
+ verify(mRecoveryWorker).triggerRestart();
+ }
+
+ @Test
+ public void checkRecovering_isRecovering_showResetting() {
+ when(mRecoveryWorker.isRecovering()).thenReturn(true);
+
+ mInternetResetHelper.checkRecovering();
+
+ verify(mResettingPreference).setVisible(true);
+ }
+
+ @Test
+ public void checkRecovering_isNotRecovering_doNotShowResetting() {
+ when(mRecoveryWorker.isRecovering()).thenReturn(false);
+
+ mInternetResetHelper.checkRecovering();
+
+ verify(mResettingPreference, never()).setVisible(true);
}
}
diff --git a/tests/unit/src/com/android/settings/network/SubscriptionUtilTest.java b/tests/unit/src/com/android/settings/network/SubscriptionUtilTest.java
index 43a32b51fbc5e44ec62c6cb04a06ae1631ad45a3..63dca7e88eb31fcef46f8232275748a38d916fd6 100644
--- a/tests/unit/src/com/android/settings/network/SubscriptionUtilTest.java
+++ b/tests/unit/src/com/android/settings/network/SubscriptionUtilTest.java
@@ -25,11 +25,14 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
+import android.content.res.Resources;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
+import com.android.settings.R;
+
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -58,6 +61,8 @@ public class SubscriptionUtilTest {
private SubscriptionManager mSubMgr;
@Mock
private TelephonyManager mTelMgr;
+ @Mock
+ private Resources mResources;
@Before
@@ -443,4 +448,22 @@ public class SubscriptionUtilTest {
public void isInactiveInsertedPSim_nullSubInfo_doesNotCrash() {
assertThat(SubscriptionUtil.isInactiveInsertedPSim(null)).isFalse();
}
+
+ @Test
+ public void isSimHardwareVisible_configAsInvisible_returnFalse() {
+ when(mContext.getResources()).thenReturn(mResources);
+ when(mResources.getBoolean(R.bool.config_show_sim_info))
+ .thenReturn(false);
+
+ assertThat(SubscriptionUtil.isSimHardwareVisible(mContext)).isFalse();
+ }
+
+ @Test
+ public void isSimHardwareVisible_configAsVisible_returnTrue() {
+ when(mContext.getResources()).thenReturn(mResources);
+ when(mResources.getBoolean(R.bool.config_show_sim_info))
+ .thenReturn(true);
+
+ assertTrue(SubscriptionUtil.isSimHardwareVisible(mContext));
+ }
}
diff --git a/tests/unit/src/com/android/settings/network/UiccSlotUtilTest.java b/tests/unit/src/com/android/settings/network/UiccSlotUtilTest.java
index 4282b3e64c5eb346b6f4b7cf817cde55a7cf5bfd..9a2c61167cbf4d1f8a050eb678d0965b0ddf1d1b 100644
--- a/tests/unit/src/com/android/settings/network/UiccSlotUtilTest.java
+++ b/tests/unit/src/com/android/settings/network/UiccSlotUtilTest.java
@@ -638,6 +638,106 @@ public class UiccSlotUtilTest {
assertThat(testExcludedLogicalSlotIndex).isEqualTo(verifyExcludedLogicalSlotIndex);
}
+ @Test
+ public void isRemovableSimEnabled_noPsim_returnsFalse() {
+ when(mTelephonyManager.getUiccSlotsInfo()).thenReturn(
+ oneSimSlotDeviceActiveEsim());
+
+ boolean testSlot = UiccSlotUtil.isRemovableSimEnabled(mTelephonyManager);
+
+ assertThat(testSlot).isFalse();
+ }
+
+ @Test
+ public void isRemovableSimEnabled_activeRemovableEsimAndInactivePsim_returnsFalse() {
+ when(mTelephonyManager.getUiccSlotsInfo()).thenReturn(
+ twoSimSlotsDeviceActiveRemovableEsimInactivePsim());
+
+ boolean testSlot = UiccSlotUtil.isRemovableSimEnabled(mTelephonyManager);
+
+ assertThat(testSlot).isFalse();
+ }
+
+ @Test
+ public void isRemovableSimEnabled_activeRemovableEsimAndActivePsim_returnsTrue() {
+ when(mTelephonyManager.getUiccSlotsInfo()).thenReturn(
+ twoSimSlotsDeviceActivePsimActiveRemovableEsim());
+
+ boolean testSlot = UiccSlotUtil.isRemovableSimEnabled(mTelephonyManager);
+
+ assertThat(testSlot).isTrue();
+ }
+
+ @Test
+ public void isRemovableSimEnabled_inactiveRemovableEsimAndActivePsim_returnsTrue() {
+ when(mTelephonyManager.getUiccSlotsInfo()).thenReturn(
+ twoSimSlotsDeviceInactiveRemovableEsimActivePsim());
+
+ boolean testSlot = UiccSlotUtil.isRemovableSimEnabled(mTelephonyManager);
+
+ assertThat(testSlot).isTrue();
+ }
+
+ @Test
+ public void isRemovableSimEnabled_twoActiveRemovableEsimsAndInactivePsim_returnsFalse() {
+ when(mTelephonyManager.getUiccSlotsInfo()).thenReturn(
+ twoSimSlotsDeviceTwoActiveRemovableEsimsInactivePsim());
+
+ boolean testSlot = UiccSlotUtil.isRemovableSimEnabled(mTelephonyManager);
+
+ assertThat(testSlot).isFalse();
+ }
+
+ @Test
+ public void isRemovableSimEnabled_oneActiveOneInactiveRemovableEsimActivePsim_returnsTrue() {
+ when(mTelephonyManager.getUiccSlotsInfo()).thenReturn(
+ twoSimSlotsDeviceOneActiveOneInactiveRemovableEsimsActivePsim());
+
+ boolean testSlot = UiccSlotUtil.isRemovableSimEnabled(mTelephonyManager);
+
+ assertThat(testSlot).isTrue();
+ }
+
+ @Test
+ public void isRemovableSimEnabled_activePsim_returnsTrue() {
+ when(mTelephonyManager.getUiccSlotsInfo()).thenReturn(
+ oneSimSlotDeviceActivePsim());
+
+ boolean testSlot = UiccSlotUtil.isRemovableSimEnabled(mTelephonyManager);
+
+ assertThat(testSlot).isTrue();
+ }
+
+ @Test
+ public void isRemovableSimEnabled_inactivePsim_returnsFalse() {
+ when(mTelephonyManager.getUiccSlotsInfo()).thenReturn(
+ oneSimSlotDeviceinactivePsim());
+
+ boolean testSlot = UiccSlotUtil.isRemovableSimEnabled(mTelephonyManager);
+
+ assertThat(testSlot).isFalse();
+ }
+
+ @Test
+ public void isRemovableSimEnabled_activeEsimAndActivePsim_returnsTrue() {
+ when(mTelephonyManager.getUiccSlotsInfo()).thenReturn(
+ twoSimSlotsDeviceActivePsimActiveEsim());
+
+ boolean testSlot = UiccSlotUtil.isRemovableSimEnabled(mTelephonyManager);
+
+ assertThat(testSlot).isTrue();
+ }
+
+ @Test
+ public void isRemovableSimEnabled_activeEsimAndInactivePsim_returnsFalse() {
+ when(mTelephonyManager.getUiccSlotsInfo()).thenReturn(
+ twoSimSlotsDeviceInactivePsimActiveEsim());
+
+ boolean testSlot = UiccSlotUtil.isRemovableSimEnabled(mTelephonyManager);
+
+ assertThat(testSlot).isFalse();
+ }
+
private void compareTwoUiccSlotMappings(Collection testUiccSlotMappings,
Collection verifyUiccSlotMappings) {
assertThat(testUiccSlotMappings.size()).isEqualTo(verifyUiccSlotMappings.size());
@@ -792,6 +892,10 @@ public class UiccSlotUtilTest {
return new UiccSlotInfo[]{createUiccSlotInfo(true, false, 1, true)};
}
+ private UiccSlotInfo[] oneSimSlotDeviceinactivePsim() {
+ return new UiccSlotInfo[]{createUiccSlotInfo(false, true, -1, false)};
+ }
+
private UiccSlotInfo[] twoSimSlotsDeviceActivePsimActiveEsim() {
return new UiccSlotInfo[]{
createUiccSlotInfo(false, true, 0, true),
@@ -810,6 +914,30 @@ public class UiccSlotUtilTest {
createUiccSlotInfo(true, true, 1, true)};
}
+ private UiccSlotInfo[] twoSimSlotsDeviceActiveRemovableEsimInactivePsim() {
+ return new UiccSlotInfo[]{
+ createUiccSlotInfo(true, true, 0, true),
+ createUiccSlotInfo(false, true, -1, false)};
+ }
+
+ private UiccSlotInfo[] twoSimSlotsDeviceInactiveRemovableEsimActivePsim() {
+ return new UiccSlotInfo[]{
+ createUiccSlotInfo(true, true, -1, false),
+ createUiccSlotInfo(false, true, 0, true)};
+ }
+
+ private UiccSlotInfo[] twoSimSlotsDeviceTwoActiveRemovableEsimsInactivePsim() {
+ return new UiccSlotInfo[]{
+ createUiccSlotInfoForRemovableEsimMep(0, true, 1, true),
+ createUiccSlotInfo(false, true, -1, false)};
+ }
+
+ private UiccSlotInfo[] twoSimSlotsDeviceOneActiveOneInactiveRemovableEsimsActivePsim() {
+ return new UiccSlotInfo[]{
+ createUiccSlotInfoForRemovableEsimMep(1, true, -1, false),
+ createUiccSlotInfo(false, true, 0, true)};
+ }
+
private UiccSlotInfo[] twoSimSlotsDeviceActiveEsimActivePsim() {
return new UiccSlotInfo[]{
createUiccSlotInfo(true, false, 0, true),
@@ -872,4 +1000,20 @@ public class UiccSlotUtilTest {
logicalSlotIdx2 /* logicalSlotIdx */,
isActiveEsim2 /* isActive */)));
}
+
+ private UiccSlotInfo createUiccSlotInfoForRemovableEsimMep(int logicalSlotIdx1,
+ boolean isActiveEsim1, int logicalSlotIdx2, boolean isActiveEsim2) {
+ return new UiccSlotInfo(
+ true, /* isEuicc */
+ "123", /* cardId */
+ CARD_STATE_INFO_PRESENT, /* cardStateInfo */
+ true, /* isExtendApduSupported */
+ true, /* isRemovable */
+ Arrays.asList(
+ new UiccPortInfo("" /* iccId */, 0 /* portIdx */,
+ logicalSlotIdx1 /* logicalSlotIdx */, isActiveEsim1 /* isActive */),
+ new UiccPortInfo("" /* iccId */, 1 /* portIdx */,
+ logicalSlotIdx2 /* logicalSlotIdx */,
+ isActiveEsim2 /* isActive */)));
+ }
}
diff --git a/tests/unit/src/com/android/settings/testutils/FakeFeatureFactory.java b/tests/unit/src/com/android/settings/testutils/FakeFeatureFactory.java
index f565075736dea9de20c7de1a41ce22a9b6bd67fb..717de791c553db53cb52f10e42ce7bb05a0da43b 100644
--- a/tests/unit/src/com/android/settings/testutils/FakeFeatureFactory.java
+++ b/tests/unit/src/com/android/settings/testutils/FakeFeatureFactory.java
@@ -45,7 +45,6 @@ import com.android.settings.security.SecurityFeatureProvider;
import com.android.settings.security.SecuritySettingsFeatureProvider;
import com.android.settings.slices.SlicesFeatureProvider;
import com.android.settings.users.UserFeatureProvider;
-import com.android.settings.vpn2.AdvancedVpnFeatureProvider;
import com.android.settings.wifi.WifiTrackerLibProvider;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
@@ -83,7 +82,6 @@ public class FakeFeatureFactory extends FeatureFactory {
public SecuritySettingsFeatureProvider securitySettingsFeatureProvider;
public AccessibilitySearchFeatureProvider mAccessibilitySearchFeatureProvider;
public AccessibilityMetricsFeatureProvider mAccessibilityMetricsFeatureProvider;
- public AdvancedVpnFeatureProvider mAdvancedVpnFeatureProvider;
/**
* Call this in {@code @Before} method of the test class to use fake factory.
@@ -124,7 +122,6 @@ public class FakeFeatureFactory extends FeatureFactory {
securitySettingsFeatureProvider = mock(SecuritySettingsFeatureProvider.class);
mAccessibilitySearchFeatureProvider = mock(AccessibilitySearchFeatureProvider.class);
mAccessibilityMetricsFeatureProvider = mock(AccessibilityMetricsFeatureProvider.class);
- mAdvancedVpnFeatureProvider = mock(AdvancedVpnFeatureProvider.class);
}
@Override
@@ -261,9 +258,4 @@ public class FakeFeatureFactory extends FeatureFactory {
public AccessibilityMetricsFeatureProvider getAccessibilityMetricsFeatureProvider() {
return mAccessibilityMetricsFeatureProvider;
}
-
- @Override
- public AdvancedVpnFeatureProvider getAdvancedVpnFeatureProvider() {
- return mAdvancedVpnFeatureProvider;
- }
}
diff --git a/tests/unit/src/com/android/settings/vpn2/AppManagementFragmentTest.java b/tests/unit/src/com/android/settings/vpn2/AppManagementFragmentTest.java
deleted file mode 100644
index 80bb39372c01212467c471d9d7ef603fc14f90aa..0000000000000000000000000000000000000000
--- a/tests/unit/src/com/android/settings/vpn2/AppManagementFragmentTest.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Copyright (C) 2022 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.vpn2;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
-
-import android.content.Context;
-import android.os.Looper;
-
-import androidx.test.annotation.UiThreadTest;
-import androidx.test.core.app.ApplicationProvider;
-import androidx.test.ext.junit.runners.AndroidJUnit4;
-
-import com.android.settings.testutils.FakeFeatureFactory;
-import com.android.settingslib.RestrictedPreference;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.junit.MockitoJUnit;
-import org.mockito.junit.MockitoRule;
-
-@RunWith(AndroidJUnit4.class)
-public class AppManagementFragmentTest {
- private static final String FAKE_PACKAGE_NAME = "com.fake.package.name";
- private static final String ADVANCED_VPN_GROUP_PACKAGE_NAME = "com.advanced.package.name";
-
- @Rule
- public final MockitoRule mMockitoRule = MockitoJUnit.rule();
-
- private AppManagementFragment mFragment;
- private Context mContext;
- private FakeFeatureFactory mFakeFeatureFactory;
- private RestrictedPreference mPreferenceForget;
-
- @Before
- @UiThreadTest
- public void setUp() {
- if (Looper.myLooper() == null) {
- Looper.prepare();
- }
-
- mFragment = spy(new AppManagementFragment());
- mContext = spy(ApplicationProvider.getApplicationContext());
- mPreferenceForget = new RestrictedPreference(mContext);
-
- mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
- mFragment.init(ADVANCED_VPN_GROUP_PACKAGE_NAME,
- mFakeFeatureFactory.getAdvancedVpnFeatureProvider(), mPreferenceForget);
- when(mFakeFeatureFactory.mAdvancedVpnFeatureProvider.getAdvancedVpnPackageName())
- .thenReturn(ADVANCED_VPN_GROUP_PACKAGE_NAME);
- when(mFakeFeatureFactory.mAdvancedVpnFeatureProvider.isAdvancedVpnSupported(any()))
- .thenReturn(true);
- }
-
- @Test
- public void updateRestrictedViews_isAdvancedVpn_hidesForgetPreference() {
- when(mFakeFeatureFactory.mAdvancedVpnFeatureProvider.isAdvancedVpnRemovable())
- .thenReturn(false);
- mFragment.updateRestrictedViews();
- assertThat(mPreferenceForget.isVisible()).isFalse();
- }
-
- @Test
- public void updateRestrictedViews_isNotAdvancedVpn_showsForgetPreference() {
- when(mFakeFeatureFactory.mAdvancedVpnFeatureProvider.isAdvancedVpnRemovable())
- .thenReturn(false);
- mFragment.init(FAKE_PACKAGE_NAME,
- mFakeFeatureFactory.getAdvancedVpnFeatureProvider(), mPreferenceForget);
- mFragment.updateRestrictedViews();
- assertThat(mPreferenceForget.isVisible()).isTrue();
- }
-
- @Test
- public void updateRestrictedViews_isAdvancedVpnRemovable_showsForgetPreference() {
- when(mFakeFeatureFactory.mAdvancedVpnFeatureProvider.isAdvancedVpnRemovable())
- .thenReturn(true);
- mFragment.init(FAKE_PACKAGE_NAME,
- mFakeFeatureFactory.getAdvancedVpnFeatureProvider(), mPreferenceForget);
- mFragment.updateRestrictedViews();
- assertThat(mPreferenceForget.isVisible()).isTrue();
- }
-}
diff --git a/tests/unit/src/com/android/settings/vpn2/VpnSettingsTest.java b/tests/unit/src/com/android/settings/vpn2/VpnSettingsTest.java
deleted file mode 100644
index 953a524750d1874beb1189cf89a35bd4346133a7..0000000000000000000000000000000000000000
--- a/tests/unit/src/com/android/settings/vpn2/VpnSettingsTest.java
+++ /dev/null
@@ -1,285 +0,0 @@
-/*
- * Copyright (C) 2022 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.vpn2;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyInt;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.app.AppOpsManager;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageManager;
-import android.os.Looper;
-import android.os.UserHandle;
-import android.text.TextUtils;
-import android.util.ArraySet;
-
-import androidx.preference.Preference;
-import androidx.preference.PreferenceCategory;
-import androidx.preference.PreferenceGroup;
-import androidx.preference.PreferenceManager;
-import androidx.preference.PreferenceScreen;
-import androidx.test.annotation.UiThreadTest;
-import androidx.test.core.app.ApplicationProvider;
-import androidx.test.ext.junit.runners.AndroidJUnit4;
-
-import com.android.settings.testutils.FakeFeatureFactory;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnit;
-import org.mockito.junit.MockitoRule;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-
-@RunWith(AndroidJUnit4.class)
-public class VpnSettingsTest {
- private static final int USER_ID_1 = UserHandle.USER_NULL;
- private static final String VPN_GROUP_KEY = "vpn_group";
- private static final String VPN_GROUP_TITLE = "vpn_group_title";
- private static final String VPN_PACKAGE_NAME = "vpn.package.name";
- private static final String VPN_LAUNCH_INTENT = "vpn.action";
- private static final String ADVANCED_VPN_GROUP_KEY = "advanced_vpn_group";
- private static final String ADVANCED_VPN_GROUP_TITLE = "advanced_vpn_group_title";
- private static final String ADVANCED_VPN_PACKAGE_NAME = "advanced.vpn.package.name";
- private static final String ADVANCED_VPN_LAUNCH_INTENT = "advanced.vpn.action";
-
- private final Intent mVpnIntent = new Intent().setAction(VPN_LAUNCH_INTENT);
- private final Intent mAdvancedVpnIntent = new Intent().setAction(ADVANCED_VPN_LAUNCH_INTENT);
-
- @Rule
- public final MockitoRule mMockitoRule = MockitoJUnit.rule();
-
- @Mock
- private AppOpsManager mAppOpsManager;
- @Mock
- private PackageManager mPackageManager;
-
- private VpnSettings mVpnSettings;
- private Context mContext;
- private PreferenceManager mPreferenceManager;
- private PreferenceScreen mPreferenceScreen;
- private PreferenceGroup mAdvancedVpnGroup;
- private PreferenceGroup mVpnGroup;
- private FakeFeatureFactory mFakeFeatureFactory;
-
- @Before
- @UiThreadTest
- public void setUp() throws PackageManager.NameNotFoundException {
- if (Looper.myLooper() == null) {
- Looper.prepare();
- }
-
- mVpnSettings = spy(new VpnSettings());
- mContext = spy(ApplicationProvider.getApplicationContext());
- mAdvancedVpnGroup = spy(new PreferenceCategory(mContext));
- mVpnGroup = spy(new PreferenceCategory(mContext));
- mAdvancedVpnGroup.setKey(ADVANCED_VPN_GROUP_KEY);
- mVpnGroup.setKey(VPN_GROUP_KEY);
- mPreferenceManager = new PreferenceManager(mContext);
- mPreferenceScreen = mPreferenceManager.createPreferenceScreen(mContext);
- mPreferenceScreen.addPreference(mAdvancedVpnGroup);
- mPreferenceScreen.addPreference(mVpnGroup);
- mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
- mVpnSettings.init(mPreferenceScreen, mFakeFeatureFactory.getAdvancedVpnFeatureProvider());
-
- when(mVpnSettings.getContext()).thenReturn(mContext);
- when(mFakeFeatureFactory.mAdvancedVpnFeatureProvider
- .getAdvancedVpnPreferenceGroupTitle(mContext)).thenReturn(ADVANCED_VPN_GROUP_TITLE);
- when(mFakeFeatureFactory.mAdvancedVpnFeatureProvider.getVpnPreferenceGroupTitle(mContext))
- .thenReturn(VPN_GROUP_TITLE);
- when(mFakeFeatureFactory.mAdvancedVpnFeatureProvider.getAdvancedVpnPackageName())
- .thenReturn(ADVANCED_VPN_PACKAGE_NAME);
- when(mFakeFeatureFactory.mAdvancedVpnFeatureProvider.isAdvancedVpnSupported(any()))
- .thenReturn(true);
- when(mContext.getPackageManager()).thenReturn(mPackageManager);
- doReturn(mContext).when(mContext).createContextAsUser(any(), anyInt());
- doReturn(mContext).when(mContext).createPackageContextAsUser(any(), anyInt(), any());
- doReturn(mPreferenceManager).when(mVpnGroup).getPreferenceManager();
- doReturn(mPreferenceManager).when(mAdvancedVpnGroup).getPreferenceManager();
- }
-
- @Test
- public void setShownAdvancedPreferences_hasGeneralVpn_returnsVpnCountAs1() {
- Set updates = new ArraySet<>();
- AppPreference pref =
- spy(new AppPreference(mContext, USER_ID_1, VPN_PACKAGE_NAME));
- updates.add(pref);
-
- mVpnSettings.setShownAdvancedPreferences(updates);
-
- assertThat(mVpnGroup.getPreferenceCount()).isEqualTo(1);
- assertThat(mVpnGroup.isVisible()).isTrue();
- assertThat(mAdvancedVpnGroup.isVisible()).isFalse();
- }
-
- @Test
- public void setShownAdvancedPreferences_hasAdvancedVpn_returnsAdvancedVpnCountAs1() {
- Set updates = new ArraySet<>();
- AppPreference pref =
- spy(new AppPreference(mContext, USER_ID_1, ADVANCED_VPN_PACKAGE_NAME));
- updates.add(pref);
-
- mVpnSettings.setShownAdvancedPreferences(updates);
-
- assertThat(mAdvancedVpnGroup.getPreferenceCount()).isEqualTo(1);
- assertThat(mAdvancedVpnGroup.isVisible()).isTrue();
- assertThat(mVpnGroup.isVisible()).isFalse();
- }
-
- @Test
- public void setShownAdvancedPreferences_noVpn_returnsEmpty() {
- Set updates = new ArraySet<>();
-
- mVpnSettings.setShownAdvancedPreferences(updates);
-
- assertThat(mAdvancedVpnGroup.getPreferenceCount()).isEqualTo(0);
- assertThat(mVpnGroup.getPreferenceCount()).isEqualTo(0);
- assertThat(mAdvancedVpnGroup.isVisible()).isFalse();
- assertThat(mVpnGroup.isVisible()).isFalse();
- }
-
- @Test
- public void getVpnApps_isAdvancedVpn_returnsOne() throws Exception {
- ApplicationInfo info = new ApplicationInfo();
- info.uid = 1111;
- when(mPackageManager.getApplicationInfo(anyString(), anyInt())).thenReturn(info);
-
- assertThat(VpnSettings.getVpnApps(mContext, /* includeProfiles= */ false,
- mFakeFeatureFactory.getAdvancedVpnFeatureProvider(),
- mAppOpsManager).size()).isEqualTo(1);
- }
-
- @Test
- public void getVpnApps_isNotAdvancedVpn_returnsEmpty() {
- int uid = 1111;
- List opEntries = new ArrayList<>();
- List apps = new ArrayList<>();
- AppOpsManager.PackageOps packageOps =
- new AppOpsManager.PackageOps(VPN_PACKAGE_NAME, uid, opEntries);
- apps.add(packageOps);
- when(mAppOpsManager.getPackagesForOps((int[]) any())).thenReturn(apps);
- when(mFakeFeatureFactory.mAdvancedVpnFeatureProvider.isAdvancedVpnSupported(any()))
- .thenReturn(false);
-
- assertThat(VpnSettings.getVpnApps(mContext, /* includeProfiles= */ false,
- mFakeFeatureFactory.getAdvancedVpnFeatureProvider(),
- mAppOpsManager)).isEmpty();
- }
-
- @Test
- public void clickVpn_VpnConnected_doesNotStartVpnLaunchIntent()
- throws PackageManager.NameNotFoundException {
- Set updates = new ArraySet<>();
- AppPreference pref = spy(new AppPreference(mContext, USER_ID_1, VPN_PACKAGE_NAME));
- pref.setState(AppPreference.STATE_CONNECTED);
- updates.add(pref);
- when(mContext.createPackageContextAsUser(any(), anyInt(), any())).thenReturn(mContext);
- when(mContext.getPackageManager()).thenReturn(mPackageManager);
- when(mPackageManager.getLaunchIntentForPackage(any())).thenReturn(mVpnIntent);
- ArgumentCaptor captor = ArgumentCaptor.forClass(Intent.class);
- doNothing().when(mContext).startActivityAsUser(captor.capture(), any());
- mVpnSettings.setShownPreferences(updates);
-
- mVpnSettings.onPreferenceClick(pref);
-
- verify(mContext, never()).startActivityAsUser(any(), any());
- }
-
- @Test
- public void clickVpn_VpnDisconnected_startsVpnLaunchIntent()
- throws PackageManager.NameNotFoundException {
- Set updates = new ArraySet<>();
- AppPreference pref = spy(new AppPreference(mContext, USER_ID_1, VPN_PACKAGE_NAME));
- pref.setState(AppPreference.STATE_DISCONNECTED);
- updates.add(pref);
- when(mContext.createPackageContextAsUser(any(), anyInt(), any())).thenReturn(mContext);
- when(mContext.getPackageManager()).thenReturn(mPackageManager);
- when(mPackageManager.getLaunchIntentForPackage(any())).thenReturn(mVpnIntent);
- ArgumentCaptor captor = ArgumentCaptor.forClass(Intent.class);
- doNothing().when(mContext).startActivityAsUser(captor.capture(), any());
- mVpnSettings.setShownPreferences(updates);
-
- mVpnSettings.onPreferenceClick(pref);
-
- verify(mContext).startActivityAsUser(captor.capture(), any());
- assertThat(TextUtils.equals(captor.getValue().getAction(),
- VPN_LAUNCH_INTENT)).isTrue();
- }
-
- @Test
- public void clickAdvancedVpn_VpnConnectedDisconnectDialogDisabled_startsAppLaunchIntent()
- throws PackageManager.NameNotFoundException {
- Set updates = new ArraySet<>();
- AppPreference pref =
- spy(new AppPreference(mContext, USER_ID_1, ADVANCED_VPN_PACKAGE_NAME));
- pref.setState(AppPreference.STATE_CONNECTED);
- updates.add(pref);
- when(mFakeFeatureFactory.mAdvancedVpnFeatureProvider.isDisconnectDialogEnabled())
- .thenReturn(false);
- when(mContext.createPackageContextAsUser(any(), anyInt(), any())).thenReturn(mContext);
- when(mContext.getPackageManager()).thenReturn(mPackageManager);
- when(mPackageManager.getLaunchIntentForPackage(any())).thenReturn(mAdvancedVpnIntent);
- ArgumentCaptor captor = ArgumentCaptor.forClass(Intent.class);
- doNothing().when(mContext).startActivityAsUser(captor.capture(), any());
- mVpnSettings.setShownAdvancedPreferences(updates);
-
- mVpnSettings.onPreferenceClick(pref);
-
- verify(mContext).startActivityAsUser(captor.capture(), any());
- assertThat(TextUtils.equals(captor.getValue().getAction(),
- ADVANCED_VPN_LAUNCH_INTENT)).isTrue();
- }
-
- @Test
- public void clickAdvancedVpn_VpnConnectedDisconnectDialogEnabled_doesNotStartAppLaunchIntent()
- throws PackageManager.NameNotFoundException {
- Set updates = new ArraySet<>();
- AppPreference pref =
- spy(new AppPreference(mContext, USER_ID_1, ADVANCED_VPN_PACKAGE_NAME));
- pref.setState(AppPreference.STATE_CONNECTED);
- updates.add(pref);
- when(mFakeFeatureFactory.mAdvancedVpnFeatureProvider.isDisconnectDialogEnabled())
- .thenReturn(true);
- when(mContext.createPackageContextAsUser(any(), anyInt(), any())).thenReturn(mContext);
- when(mContext.getPackageManager()).thenReturn(mPackageManager);
- when(mPackageManager.getLaunchIntentForPackage(any())).thenReturn(mAdvancedVpnIntent);
- ArgumentCaptor captor = ArgumentCaptor.forClass(Intent.class);
- doNothing().when(mContext).startActivityAsUser(captor.capture(), any());
- mVpnSettings.setShownAdvancedPreferences(updates);
-
- mVpnSettings.onPreferenceClick(pref);
-
- verify(mContext, never()).startActivityAsUser(any(), any());
- }
-}
diff --git a/tests/unit/src/com/android/settings/wifi/WifiUtilsTest.java b/tests/unit/src/com/android/settings/wifi/WifiUtilsTest.java
index 1a5e8526dc327dc5d91bb386f779f7d25836ed6e..282631026be5b19e1d24a6d1c34aea15b696f786 100644
--- a/tests/unit/src/com/android/settings/wifi/WifiUtilsTest.java
+++ b/tests/unit/src/com/android/settings/wifi/WifiUtilsTest.java
@@ -21,19 +21,53 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import android.content.Context;
+import android.content.res.Resources;
+import android.net.TetheringManager;
import android.net.wifi.SoftApConfiguration;
import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiManager;
+import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
+import com.android.settings.R;
import com.android.wifitrackerlib.WifiEntry;
+import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@RunWith(AndroidJUnit4.class)
public class WifiUtilsTest {
+ static final String[] WIFI_REGEXS = {"wifi_regexs"};
+
+ @Rule
+ public final MockitoRule mMockitoRule = MockitoJUnit.rule();
+ @Spy
+ Context mContext = ApplicationProvider.getApplicationContext();
+ @Mock
+ Resources mResources;
+ @Mock
+ WifiManager mWifiManager;
+ @Mock
+ TetheringManager mTetheringManager;
+
+ @Before
+ public void setUp() {
+ when(mContext.getResources()).thenReturn(mResources);
+ when(mResources.getBoolean(R.bool.config_show_wifi_hotspot_settings)).thenReturn(true);
+ when(mContext.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
+ when(mContext.getSystemService(TetheringManager.class)).thenReturn(mTetheringManager);
+ when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(WIFI_REGEXS);
+ }
+
@Test
public void testSSID() {
assertThat(WifiUtils.isSSIDTooLong("123")).isFalse();
@@ -108,4 +142,53 @@ public class WifiUtilsTest {
WifiConfiguration config = WifiUtils.getWifiConfig(null /* wifiEntry */,
null /* scanResult */);
}
+
+ @Test
+ public void checkShowWifiHotspot_allReady_returnTrue() {
+ assertThat(WifiUtils.checkShowWifiHotspot(mContext)).isTrue();
+ }
+
+ @Test
+ public void checkShowWifiHotspot_contextIsNull_returnFalse() {
+ assertThat(WifiUtils.checkShowWifiHotspot(null)).isFalse();
+ }
+
+ @Test
+ public void checkShowWifiHotspot_configIsNotShow_returnFalse() {
+ when(mResources.getBoolean(R.bool.config_show_wifi_hotspot_settings)).thenReturn(false);
+
+ assertThat(WifiUtils.checkShowWifiHotspot(mContext)).isFalse();
+ }
+
+ @Test
+ public void checkShowWifiHotspot_wifiManagerIsNull_returnFalse() {
+ when(mContext.getSystemService(WifiManager.class)).thenReturn(null);
+
+ assertThat(WifiUtils.checkShowWifiHotspot(mContext)).isFalse();
+ }
+
+ @Test
+ public void checkShowWifiHotspot_tetheringManagerIsNull_returnFalse() {
+ when(mContext.getSystemService(TetheringManager.class)).thenReturn(null);
+
+ assertThat(WifiUtils.checkShowWifiHotspot(mContext)).isFalse();
+ }
+
+ @Test
+ public void checkShowWifiHotspot_wifiRegexsIsEmpty_returnFalse() {
+ when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(null);
+
+ assertThat(WifiUtils.checkShowWifiHotspot(mContext)).isFalse();
+ }
+
+ @Test
+ public void canShowWifiHotspot_cachedIsReady_returnCached() {
+ WifiUtils.setCanShowWifiHotspotCached(true);
+
+ assertThat(WifiUtils.canShowWifiHotspot(null)).isTrue();
+
+ WifiUtils.setCanShowWifiHotspotCached(false);
+
+ assertThat(WifiUtils.canShowWifiHotspot(null)).isFalse();
+ }
}