Merge "Remove silky flag from tests for official release" into sc-dev
diff --git a/res/drawable/ic_arrow_forward.xml b/res/drawable/ic_arrow_forward.xml
new file mode 100644
index 0000000..078cb69
--- /dev/null
+++ b/res/drawable/ic_arrow_forward.xml
@@ -0,0 +1,26 @@
+<!--
+ 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.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24"
+ android:autoMirrored="true"
+ android:tint="?attr/colorControlNormal">
+ <path
+ android:fillColor="@android:color/white"
+ android:pathData="M6.23,20.23l1.77,1.77l10,-10l-10,-10l-1.77,1.77l8.23,8.23z"/>
+</vector>
diff --git a/res/layout/face_enroll_education.xml b/res/layout/face_enroll_education.xml
index 646856f..0149479 100644
--- a/res/layout/face_enroll_education.xml
+++ b/res/layout/face_enroll_education.xml
@@ -47,6 +47,7 @@
android:layout_height="wrap_content"
app:sudVideo="@raw/face_education"/>
+ <!-- Animation res MUST be set in code, gated by config_face_education_use_lottie. -->
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/illustration_lottie"
android:layout_width="match_parent"
@@ -54,8 +55,7 @@
android:scaleType="fitCenter"
android:visibility="invisible"
app:lottie_autoPlay="true"
- app:lottie_loop="true"
- app:lottie_rawRes="@raw/face_education_lottie" />
+ app:lottie_loop="true" />
<ImageView
android:id="@+id/illustration_accessibility"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 424f7a2..9f86901 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -98,11 +98,11 @@
<string name="font_size_make_larger_desc">Make larger</string>
<!-- Auto rotate switchbar title. [CHAR_LIMIT=NONE] -->
- <string name="auto_rotate_settings_primary_switch_title">Use Auto-Rotate</string>
+ <string name="auto_rotate_settings_primary_switch_title">Use Auto-rotate</string>
<!-- Disclaimer for camera based rotate [CHAR_LIMIT=NONE] -->
<string name="smart_rotate_text_headline">
- Face Detection uses the front-facing camera to improve Auto-Rotate accuracy. Images are never stored or sent to Google.<br><br>
+ Face Detection uses the front-facing camera to improve Auto-rotate accuracy. Images are never stored or sent to Google.<br><br>
<a href="<xliff:g example="http://www.google.com" id="url">http://support.google.com/mobile?p=telephony_rtt</xliff:g>">Learn more</a>
</string>
<string name="font_size_preview_text_headline">Sample text</string>
@@ -11471,6 +11471,9 @@
<!-- [CHAR LIMIT=60] Summary string for screen attention explaining why the toggle is disabled by battery saver-->
<string name="ambient_camera_summary_battery_saver_on">Temporarily disabled due to Battery Saver</string>
+ <!-- [CHAR LIMIT=60] Button text for screen attention to turn off battery saver-->
+ <string name="ambient_camera_battery_saver_off">Turn off battery saver</string>
+
<!-- [CHAR LIMIT=60] Summary string on dark theme explaining why the toggle is disabled while the setting is off-->
<string name="dark_ui_mode_disabled_summary_dark_theme_off">Temporarily turned on due to Battery Saver</string>
@@ -13214,6 +13217,8 @@
<string name="keywords_internet">network connection, internet, wireless, data, wifi, wi-fi, wi fi, cellular, mobile, cell carrier, 4g, 3g, 2g, lte</string>
<!-- Slice title text for turning on the Wi-Fi networks. [CHAR LIMIT=40] -->
<string name="turn_on_wifi">Turn on Wi\u2011Fi</string>
+ <!-- Slice title text for turning off the Wi-Fi networks. [CHAR LIMIT=40] -->
+ <string name="turn_off_wifi">Turn off Wi\u2011Fi</string>
<!-- Title for interrupting the voice call alert. [CHAR_LIMIT=NONE] -->
<string name="reset_your_internet_title">Reset your internet?</string>
<!-- Description for interrupting the voice call alert. [CHAR_LIMIT=NONE] -->
@@ -13228,8 +13233,8 @@
<string name="networks_available">Networks available</string>
<!-- Summary for warning to disconnect ethernet first then switch to other networks. [CHAR LIMIT=60] -->
<string name="to_switch_networks_disconnect_ethernet">To switch networks, disconnect ethernet</string>
- <!-- Panel subtitle for Wi-Fi turned on. [CHAR LIMIT=60] -->
- <string name="wifi_is_turned_on_subtitle">Wi\u2011Fi is turned on</string>
+ <!-- Panel subtitle for Wi-Fi turned off. [CHAR LIMIT=60] -->
+ <string name="wifi_is_off">Wi\u2011Fi is off</string>
<!-- Panel subtitle for tapping a network to connect to internet. [CHAR LIMIT=60] -->
<string name="tap_a_network_to_connect">Tap a network to connect</string>
<!-- Title for merged carrier Wi-Fi offload toggle. [CHAR LIMIT=NONE] -->
diff --git a/res/xml/connected_devices.xml b/res/xml/connected_devices.xml
index 75878f9..e7e3c2c 100644
--- a/res/xml/connected_devices.xml
+++ b/res/xml/connected_devices.xml
@@ -40,24 +40,13 @@
android:key="add_bt_devices"
android:title="@string/bluetooth_pairing_pref_title"
android:icon="@drawable/ic_add_24dp"
- android:fragment="com.android.settings.bluetooth.BluetoothPairingDetail"
- settings:allowDividerAbove="true"
- settings:keywords="@string/keywords_add_bt_device"
- settings:userRestriction="no_config_bluetooth"
- settings:useAdminDisabledSummary="true"
- settings:controller="com.android.settings.connecteddevice.AddDevicePreferenceController"/>
-
- <com.android.settingslib.RestrictedPreference
- android:key="add_bt_devices_summary"
- android:title="@string/bluetooth_pairing_pref_title"
- android:icon="@drawable/ic_add_24dp"
android:summary="@string/connected_device_add_device_summary"
android:fragment="com.android.settings.bluetooth.BluetoothPairingDetail"
settings:allowDividerAbove="true"
settings:keywords="@string/keywords_add_bt_device"
settings:userRestriction="no_config_bluetooth"
settings:useAdminDisabledSummary="true"
- settings:controller="com.android.settings.connecteddevice.AddDeviceSummaryPreferenceController"/>
+ settings:controller="com.android.settings.connecteddevice.AddDevicePreferenceController"/>
<PreferenceCategory
android:key="previously_connected_devices"
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index 4287810..6d4ea26 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -161,6 +161,10 @@
/** Whether or not app hibernation is enabled on the device **/
public static final String PROPERTY_APP_HIBERNATION_ENABLED = "app_hibernation_enabled";
+ /** Whether or not app hibernation targets apps that target a pre-S SDK **/
+ public static final String PROPERTY_HIBERNATION_TARGETS_PRE_S_APPS =
+ "app_hibernation_targets_pre_s_apps";
+
/** Whether or not Settings Shared Axis transition is enabled */
public static final String SETTINGS_SHARED_AXIS_ENABLED = "settings_shared_axis_enabled";
diff --git a/src/com/android/settings/applications/appinfo/HibernationSwitchPreferenceController.java b/src/com/android/settings/applications/appinfo/HibernationSwitchPreferenceController.java
index 40be629..42f862d 100644
--- a/src/com/android/settings/applications/appinfo/HibernationSwitchPreferenceController.java
+++ b/src/com/android/settings/applications/appinfo/HibernationSwitchPreferenceController.java
@@ -23,6 +23,7 @@
import static android.provider.DeviceConfig.NAMESPACE_APP_HIBERNATION;
import static com.android.settings.Utils.PROPERTY_APP_HIBERNATION_ENABLED;
+import static com.android.settings.Utils.PROPERTY_HIBERNATION_TARGETS_PRE_S_APPS;
import android.app.AppOpsManager;
import android.content.Context;
@@ -95,8 +96,11 @@
: android.os.Build.VERSION_CODES.Q;
try {
mPackageUid = packageManager.getPackageUid(packageName, /* flags */ 0);
- mIsPackageExemptByDefault = packageManager.getTargetSdkVersion(packageName)
- <= maxTargetSdkVersionForExemptApps;
+ mIsPackageExemptByDefault =
+ hibernationTargetsPreSApps()
+ ? false
+ : packageManager.getTargetSdkVersion(packageName)
+ <= maxTargetSdkVersionForExemptApps;
mIsPackageSet = true;
} catch (PackageManager.NameNotFoundException e) {
Slog.w(TAG, "Package [" + mPackageName + "] is not found!");
@@ -142,4 +146,9 @@
return DeviceConfig.getBoolean(
NAMESPACE_APP_HIBERNATION, PROPERTY_APP_HIBERNATION_ENABLED, false);
}
+
+ private static boolean hibernationTargetsPreSApps() {
+ return DeviceConfig.getBoolean(
+ NAMESPACE_APP_HIBERNATION, PROPERTY_HIBERNATION_TARGETS_PRE_S_APPS, false);
+ }
}
diff --git a/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminAdd.java b/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminAdd.java
index 3ebbc06..7b2f4ba 100644
--- a/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminAdd.java
+++ b/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminAdd.java
@@ -49,7 +49,6 @@
import android.os.UserManager;
import android.text.TextUtils;
import android.text.TextUtils.TruncateAt;
-import android.text.method.ScrollingMovementMethod;
import android.util.EventLog;
import android.util.Log;
import android.view.Display;
@@ -338,7 +337,6 @@
mActionButton = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE);
mActionButton.setFilterTouchesWhenObscured(true);
mAddMsg = dialog.findViewById(R.id.add_msg_simplified);
- mAddMsg.setMovementMethod(new ScrollingMovementMethod());
mAddMsg.setText(mAddMsgText);
mAdminWarning = dialog.findViewById(R.id.admin_warning_simplified);
mAdminWarning.setText(getString(R.string.device_admin_warning_simplified,
diff --git a/src/com/android/settings/biometrics/face/FaceEnrollEducation.java b/src/com/android/settings/biometrics/face/FaceEnrollEducation.java
index 49a4748..8e2d3f4 100644
--- a/src/com/android/settings/biometrics/face/FaceEnrollEducation.java
+++ b/src/com/android/settings/biometrics/face/FaceEnrollEducation.java
@@ -112,6 +112,7 @@
if (mIsUsingLottie) {
mIllustrationDefault.stop();
mIllustrationDefault.setVisibility(View.INVISIBLE);
+ mIllustrationLottie.setAnimation(R.raw.face_education_lottie);
mIllustrationLottie.setVisibility(View.VISIBLE);
mIllustrationLottie.playAnimation();
}
diff --git a/src/com/android/settings/bluetooth/BluetoothDeviceRenamePreferenceController.java b/src/com/android/settings/bluetooth/BluetoothDeviceRenamePreferenceController.java
index d42a1be..e8751dc 100644
--- a/src/com/android/settings/bluetooth/BluetoothDeviceRenamePreferenceController.java
+++ b/src/com/android/settings/bluetooth/BluetoothDeviceRenamePreferenceController.java
@@ -41,6 +41,12 @@
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
}
+ @Override
+ public int getAvailabilityStatus() {
+ return mBluetoothAdapter != null && mBluetoothAdapter.isEnabled()
+ ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
+ }
+
/**
* Set the {@link Fragment} that used to show {@link LocalDeviceNameDialogFragment}
* in {@code handlePreferenceTreeClick}
diff --git a/src/com/android/settings/bluetooth/BluetoothPairingService.java b/src/com/android/settings/bluetooth/BluetoothPairingService.java
index 0bff721..47565d3 100644
--- a/src/com/android/settings/bluetooth/BluetoothPairingService.java
+++ b/src/com/android/settings/bluetooth/BluetoothPairingService.java
@@ -177,6 +177,15 @@
pairingDialogIntent.setClass(this, BluetoothPairingService.class);
pairingDialogIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice);
pairingDialogIntent.putExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, type);
+
+ if (type == BluetoothDevice.PAIRING_VARIANT_PASSKEY_CONFIRMATION
+ || type == BluetoothDevice.PAIRING_VARIANT_DISPLAY_PASSKEY
+ || type == BluetoothDevice.PAIRING_VARIANT_DISPLAY_PIN) {
+ int pairingKey = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_KEY,
+ BluetoothDevice.ERROR);
+ pairingDialogIntent.putExtra(BluetoothDevice.EXTRA_PAIRING_KEY, pairingKey);
+ }
+
PendingIntent pairIntent = PendingIntent.getService(this, 0, pairingDialogIntent,
PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE);
diff --git a/src/com/android/settings/connecteddevice/AddDevicePreferenceController.java b/src/com/android/settings/connecteddevice/AddDevicePreferenceController.java
index 6fdc7e5..a2d477d 100644
--- a/src/com/android/settings/connecteddevice/AddDevicePreferenceController.java
+++ b/src/com/android/settings/connecteddevice/AddDevicePreferenceController.java
@@ -33,7 +33,7 @@
/**
* Controller to maintain the {@link androidx.preference.Preference} for add
- * device without summary at beginning. It monitor Bluetooth's status(on/off) and decide if need
+ * device. It monitor Bluetooth's status(on/off) and decide if need
* to show summary or not.
*/
public class AddDevicePreferenceController extends BasePreferenceController
@@ -43,12 +43,11 @@
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
- updateState();
+ updateState(mPreference);
}
};
private IntentFilter mIntentFilter;
-
- protected BluetoothAdapter mBluetoothAdapter;
+ private BluetoothAdapter mBluetoothAdapter;
public AddDevicePreferenceController(Context context, String key) {
super(context, key);
@@ -59,7 +58,6 @@
@Override
public void onStart() {
mContext.registerReceiver(mReceiver, mIntentFilter);
- updateState(mPreference);
}
@Override
@@ -72,13 +70,13 @@
super.displayPreference(screen);
if (isAvailable()) {
mPreference = screen.findPreference(getPreferenceKey());
+ updateState(mPreference);
}
}
@Override
public int getAvailabilityStatus() {
return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)
- && isBluetoothEnabled()
? AVAILABLE
: UNSUPPORTED_ON_DEVICE;
}
@@ -93,8 +91,4 @@
protected boolean isBluetoothEnabled() {
return mBluetoothAdapter != null && mBluetoothAdapter.isEnabled();
}
-
- void updateState() {
- updateState(mPreference);
- }
}
diff --git a/src/com/android/settings/connecteddevice/AddDeviceSummaryPreferenceController.java b/src/com/android/settings/connecteddevice/AddDeviceSummaryPreferenceController.java
deleted file mode 100644
index 4513473..0000000
--- a/src/com/android/settings/connecteddevice/AddDeviceSummaryPreferenceController.java
+++ /dev/null
@@ -1,39 +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.connecteddevice;
-
-import android.content.Context;
-import android.content.pm.PackageManager;
-
-/**
- * Controller to maintain the {@link androidx.preference.Preference} for add
- * device with summary at beginning. It monitor Bluetooth's status(on/off) and decide if need
- * to show summary or not.
- */
-public class AddDeviceSummaryPreferenceController extends AddDevicePreferenceController {
-
- public AddDeviceSummaryPreferenceController(Context context, String key) {
- super(context, key);
- }
-
- @Override
- public int getAvailabilityStatus() {
- return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)
- && !isBluetoothEnabled()
- ? AVAILABLE
- : UNSUPPORTED_ON_DEVICE;
- }
-}
diff --git a/src/com/android/settings/connecteddevice/PreviouslyConnectedDevicePreferenceController.java b/src/com/android/settings/connecteddevice/PreviouslyConnectedDevicePreferenceController.java
index 4a29485..4469d26 100644
--- a/src/com/android/settings/connecteddevice/PreviouslyConnectedDevicePreferenceController.java
+++ b/src/com/android/settings/connecteddevice/PreviouslyConnectedDevicePreferenceController.java
@@ -103,6 +103,7 @@
final Context context = screen.getContext();
mBluetoothDeviceUpdater.setPrefContext(context);
mSavedDockUpdater.setPreferenceContext(context);
+ mBluetoothDeviceUpdater.forceUpdate();
}
}
diff --git a/src/com/android/settings/core/SettingsBaseActivity.java b/src/com/android/settings/core/SettingsBaseActivity.java
index 8caae71..c5d86e1 100644
--- a/src/com/android/settings/core/SettingsBaseActivity.java
+++ b/src/com/android/settings/core/SettingsBaseActivity.java
@@ -164,84 +164,22 @@
}
@Override
- public void startActivity(Intent intent) {
- if (!Utils.isPageTransitionEnabled(this)) {
- super.startActivity(intent);
- return;
- }
-
- final int transitionType = getTransitionType(intent);
- if (transitionType == TransitionType.TRANSITION_SLIDE) {
- super.startActivity(intent, null);
- overridePendingTransition(R.anim.sud_slide_next_in, R.anim.sud_slide_next_out);
- return;
- } else if (transitionType == TransitionType.TRANSITION_NONE) {
- super.startActivity(intent, null);
- return;
- } else if (transitionType == TransitionType.TRANSITION_FADE) {
- super.startActivity(intent, null);
- overridePendingTransition(android.R.anim.fade_in, R.anim.sud_stay);
- return;
- }
- super.startActivity(intent, createActivityOptionsBundleForTransition(null));
- }
-
- @Override
- public void startActivity(Intent intent, @androidx.annotation.Nullable Bundle options) {
- final int transitionType = getTransitionType(intent);
- if (!Utils.isPageTransitionEnabled(this) ||
- transitionType == TransitionType.TRANSITION_NONE) {
- super.startActivity(intent, options);
- return;
- }
-
- if (transitionType == TransitionType.TRANSITION_SLIDE) {
- super.startActivity(intent, options);
- overridePendingTransition(R.anim.sud_slide_next_in, R.anim.sud_slide_next_out);
- return;
- }
- super.startActivity(intent, createActivityOptionsBundleForTransition(options));
- }
-
- @Override
- public void startActivityForResult(Intent intent, int requestCode) {
- final int transitionType = getTransitionType(intent);
- // startActivity() will eventually calls startActivityForResult() with requestCode -1.
- // Adding this condition to avoid multiple calls.
- if (!Utils.isPageTransitionEnabled(this) || requestCode == DEFAULT_REQUEST
- || transitionType == TransitionType.TRANSITION_NONE) {
- super.startActivityForResult(intent, requestCode);
- return;
- }
-
- if (transitionType == TransitionType.TRANSITION_SLIDE) {
- super.startActivityForResult(intent, requestCode, null);
- overridePendingTransition(R.anim.sud_slide_next_in, R.anim.sud_slide_next_out);
- return;
- }
-
- super.startActivityForResult(intent, requestCode,
- createActivityOptionsBundleForTransition(null));
- }
-
- @Override
public void startActivityForResult(Intent intent, int requestCode,
@androidx.annotation.Nullable Bundle options) {
final int transitionType = getTransitionType(intent);
- if (!Utils.isPageTransitionEnabled(this) || requestCode == DEFAULT_REQUEST
- || transitionType == TransitionType.TRANSITION_NONE) {
- super.startActivityForResult(intent, requestCode, options);
+ if (Utils.isPageTransitionEnabled(this) &&
+ transitionType == TransitionType.TRANSITION_SHARED_AXIS) {
+ super.startActivityForResult(intent, requestCode,
+ createActivityOptionsBundleForTransition(options));
return;
}
+ super.startActivityForResult(intent, requestCode, options);
if (transitionType == TransitionType.TRANSITION_SLIDE) {
- super.startActivityForResult(intent, requestCode, options);
overridePendingTransition(R.anim.sud_slide_next_in, R.anim.sud_slide_next_out);
- return;
+ } else if (transitionType == TransitionType.TRANSITION_FADE) {
+ overridePendingTransition(android.R.anim.fade_in, R.anim.sud_stay);
}
-
- super.startActivityForResult(intent, requestCode,
- createActivityOptionsBundleForTransition(options));
}
@Override
diff --git a/src/com/android/settings/display/SmartAutoRotateBatterySaverController.java b/src/com/android/settings/display/SmartAutoRotateBatterySaverController.java
index 9bb2196..d135d4b 100644
--- a/src/com/android/settings/display/SmartAutoRotateBatterySaverController.java
+++ b/src/com/android/settings/display/SmartAutoRotateBatterySaverController.java
@@ -70,7 +70,7 @@
super.displayPreference(screen);
mPreference = screen.findPreference(getPreferenceKey());
((BannerMessagePreference) mPreference)
- .setPositiveButtonText(R.string.disable_text)
+ .setPositiveButtonText(R.string.ambient_camera_battery_saver_off)
.setPositiveButtonOnClickListener(v -> {
mPowerManager.setPowerSaveModeEnabled(false);
});
diff --git a/src/com/android/settings/fuelgauge/BatteryChartPreferenceController.java b/src/com/android/settings/fuelgauge/BatteryChartPreferenceController.java
index dbbafe6..ffbd2d9 100644
--- a/src/com/android/settings/fuelgauge/BatteryChartPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/BatteryChartPreferenceController.java
@@ -189,6 +189,8 @@
mPrefContext = screen.getContext();
mAppListPrefGroup = screen.findPreference(mPreferenceKey);
mAppListPrefGroup.setOrderingAsAdded(false);
+ mAppListPrefGroup.setTitle(
+ mPrefContext.getString(R.string.battery_app_usage_for_past_24));
mFooterPreference = screen.findPreference(KEY_FOOTER_PREF);
// Removes footer first until usage data is loaded to avoid flashing.
if (mFooterPreference != null) {
@@ -216,15 +218,6 @@
final BatteryHistEntry histEntry = diffEntry.mBatteryHistEntry;
final String packageName = histEntry.mPackageName;
final boolean isAppEntry = histEntry.isAppEntry();
- // Checks whether the package is installed or not.
- boolean isValidPackage = true;
- if (isAppEntry) {
- if (mBatteryUtils == null) {
- mBatteryUtils = BatteryUtils.getInstance(mPrefContext);
- }
- isValidPackage = mBatteryUtils.getPackageUid(packageName)
- != BatteryUtils.UID_NULL;
- }
mMetricsFeatureProvider.action(
mPrefContext,
isAppEntry
@@ -233,15 +226,12 @@
new Pair(ConvertUtils.METRIC_KEY_PACKAGE, packageName),
new Pair(ConvertUtils.METRIC_KEY_BATTERY_LEVEL, histEntry.mBatteryLevel),
new Pair(ConvertUtils.METRIC_KEY_BATTERY_USAGE, powerPref.getPercent()));
- Log.d(TAG, String.format("handleClick() label=%s key=%s isValid:%b\n%s",
- diffEntry.getAppLabel(), histEntry.getKey(), isValidPackage, histEntry));
- if (isValidPackage) {
- AdvancedPowerUsageDetail.startBatteryDetailPage(
+ Log.d(TAG, String.format("handleClick() label=%s key=%s enntry=\n%s",
+ diffEntry.getAppLabel(), histEntry.getKey(), histEntry));
+ AdvancedPowerUsageDetail.startBatteryDetailPage(
mActivity, mFragment, diffEntry, powerPref.getPercent(),
isValidToShowSummary(packageName), getSlotInformation());
- return true;
- }
- return false;
+ return true;
}
@Override
@@ -434,6 +424,7 @@
pref.setSingleLineTitle(true);
// Sets the BatteryDiffEntry to preference for launching detailed page.
pref.setBatteryDiffEntry(entry);
+ pref.setEnabled(entry.validForRestriction());
setPreferenceSummary(pref, entry);
if (!isAdded) {
mAppListPrefGroup.addPreference(pref);
diff --git a/src/com/android/settings/fuelgauge/BatteryDiffEntry.java b/src/com/android/settings/fuelgauge/BatteryDiffEntry.java
index 9db29f3..c6b2d45 100644
--- a/src/com/android/settings/fuelgauge/BatteryDiffEntry.java
+++ b/src/com/android/settings/fuelgauge/BatteryDiffEntry.java
@@ -39,6 +39,8 @@
static Locale sCurrentLocale = null;
// Caches app label and icon to improve loading performance.
static final Map<String, BatteryEntry.NameAndIcon> sResourceCache = new HashMap<>();
+ // Whether a specific item is valid to launch restriction page?
+ static final Map<String, Boolean> sValidForRestriction = new HashMap<>();
/** A comparator for {@link BatteryDiffEntry} based on consumed percentage. */
public static final Comparator<BatteryDiffEntry> COMPARATOR =
@@ -60,6 +62,7 @@
@VisibleForTesting String mAppLabel = null;
@VisibleForTesting Drawable mAppIcon = null;
@VisibleForTesting boolean mIsLoaded = false;
+ @VisibleForTesting boolean mValidForRestriction = true;
public BatteryDiffEntry(
Context context,
@@ -129,6 +132,12 @@
? mDefaultPackageName : mBatteryHistEntry.mPackageName;
}
+ /** Whether this item is valid for users to launch restriction page? */
+ public boolean validForRestriction() {
+ loadLabelAndIcon();
+ return mValidForRestriction;
+ }
+
/** Whether the current BatteryDiffEntry is system component or not. */
public boolean isSystemEntry() {
switch (mBatteryHistEntry.mConsumerType) {
@@ -146,7 +155,29 @@
if (mIsLoaded) {
return;
}
+ // Checks whether we have cached data or not first before fetching.
+ final BatteryEntry.NameAndIcon nameAndIcon = getCache();
+ if (nameAndIcon != null) {
+ mAppLabel = nameAndIcon.name;
+ mAppIcon = nameAndIcon.icon;
+ mAppIconId = nameAndIcon.iconId;
+ }
+ final Boolean validForRestriction = sValidForRestriction.get(getKey());
+ if (validForRestriction != null) {
+ mValidForRestriction = validForRestriction;
+ }
+ // Both nameAndIcon and restriction configuration have cached data.
+ if (nameAndIcon != null && validForRestriction != null) {
+ Log.w(TAG, String.format("cannot find cache data nameAndIcon:%s "
+ + "validForRestriction:%s", nameAndIcon, validForRestriction));
+ return;
+ }
mIsLoaded = true;
+
+ // Configures whether we can launch restriction page or not.
+ updateRestrictionFlagState();
+ sValidForRestriction.put(getKey(), Boolean.valueOf(mValidForRestriction));
+
// Loads application icon and label based on consumer type.
switch (mBatteryHistEntry.mConsumerType) {
case ConvertUtils.CONSUMER_TYPE_USER_BATTERY:
@@ -156,6 +187,9 @@
if (nameAndIconForUser != null) {
mAppIcon = nameAndIconForUser.icon;
mAppLabel = nameAndIconForUser.name;
+ sResourceCache.put(
+ getKey(),
+ new BatteryEntry.NameAndIcon(mAppLabel, mAppIcon, /*iconId=*/ 0));
}
break;
case ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY:
@@ -168,15 +202,12 @@
mAppIconId = nameAndIconForSystem.iconId;
mAppIcon = mContext.getDrawable(nameAndIconForSystem.iconId);
}
+ sResourceCache.put(
+ getKey(),
+ new BatteryEntry.NameAndIcon(mAppLabel, mAppIcon, mAppIconId));
}
break;
case ConvertUtils.CONSUMER_TYPE_UID_BATTERY:
- final BatteryEntry.NameAndIcon nameAndIcon = getCache();
- if (nameAndIcon != null) {
- mAppLabel = nameAndIcon.name;
- mAppIcon = nameAndIcon.icon;
- break;
- }
loadNameAndIconForUid();
// Uses application default icon if we cannot find it from package.
if (mAppIcon == null) {
@@ -186,13 +217,47 @@
mAppIcon = getBadgeIconForUser(mAppIcon);
if (mAppLabel != null || mAppIcon != null) {
sResourceCache.put(
- mBatteryHistEntry.getKey(),
+ getKey(),
new BatteryEntry.NameAndIcon(mAppLabel, mAppIcon, /*iconId=*/ 0));
}
break;
}
}
+ @VisibleForTesting
+ String getKey() {
+ return mBatteryHistEntry.getKey();
+ }
+
+ @VisibleForTesting
+ void updateRestrictionFlagState() {
+ mValidForRestriction = true;
+ if (!mBatteryHistEntry.isAppEntry()) {
+ return;
+ }
+ final boolean isValidPackage =
+ BatteryUtils.getInstance(mContext).getPackageUid(getPackageName())
+ != BatteryUtils.UID_NULL;
+ if (!isValidPackage) {
+ mValidForRestriction = false;
+ return;
+ }
+ try {
+ mValidForRestriction =
+ mContext.getPackageManager().getPackageInfo(
+ getPackageName(),
+ PackageManager.MATCH_DISABLED_COMPONENTS
+ | PackageManager.MATCH_ANY_USER
+ | PackageManager.GET_SIGNATURES
+ | PackageManager.GET_PERMISSIONS)
+ != null;
+ } catch (Exception e) {
+ Log.e(TAG, String.format("getPackageInfo() error %s for package=%s",
+ e.getCause(), getPackageName()));
+ mValidForRestriction = false;
+ }
+ }
+
private BatteryEntry.NameAndIcon getCache() {
final Locale locale = Locale.getDefault();
if (sCurrentLocale != locale) {
@@ -201,7 +266,7 @@
sCurrentLocale = locale;
clearCache();
}
- return sResourceCache.get(mBatteryHistEntry.getKey());
+ return sResourceCache.get(getKey());
}
private void loadNameAndIconForUid() {
@@ -258,7 +323,8 @@
public String toString() {
final StringBuilder builder = new StringBuilder()
.append("BatteryDiffEntry{")
- .append("\n\tname=" + mAppLabel)
+ .append(String.format("\n\tname=%s restrictable=%b",
+ mAppLabel, mValidForRestriction))
.append(String.format("\n\tconsume=%.2f%% %f/%f",
mPercentOfTotal, mConsumePower, mTotalConsumePower))
.append(String.format("\n\tforeground:%s background:%s",
@@ -274,6 +340,7 @@
static void clearCache() {
sResourceCache.clear();
+ sValidForRestriction.clear();
}
private Drawable getBadgeIconForUser(Drawable icon) {
diff --git a/src/com/android/settings/fuelgauge/BatteryEntry.java b/src/com/android/settings/fuelgauge/BatteryEntry.java
index 636d265..125409c 100644
--- a/src/com/android/settings/fuelgauge/BatteryEntry.java
+++ b/src/com/android/settings/fuelgauge/BatteryEntry.java
@@ -241,7 +241,10 @@
mBatteryConsumer = null;
mIsHidden = false;
mPowerComponentId = powerComponentId;
- mConsumedPower = devicePowerMah;
+ mConsumedPower =
+ powerComponentId == BatteryConsumer.POWER_COMPONENT_SCREEN
+ ? devicePowerMah
+ : devicePowerMah - appsPowerMah;
mUsageDurationMs = usageDurationMs;
mConsumerType = ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY;
@@ -264,8 +267,10 @@
iconId = R.drawable.ic_power_system;
icon = context.getDrawable(iconId);
name = powerComponentName;
-
- mConsumedPower = devicePowerMah;
+ mConsumedPower =
+ powerComponentId == BatteryConsumer.POWER_COMPONENT_SCREEN
+ ? devicePowerMah
+ : devicePowerMah - appsPowerMah;
mConsumerType = ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY;
}
diff --git a/src/com/android/settings/network/ProviderModelSlice.java b/src/com/android/settings/network/ProviderModelSlice.java
index 6b6180b..b778a05 100644
--- a/src/com/android/settings/network/ProviderModelSlice.java
+++ b/src/com/android/settings/network/ProviderModelSlice.java
@@ -22,9 +22,12 @@
import static com.android.settings.slices.CustomSliceRegistry.PROVIDER_MODEL_SLICE_URI;
import android.annotation.ColorInt;
+import android.app.PendingIntent;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.Intent;
+import android.graphics.Color;
+import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.telephony.SubscriptionManager;
@@ -150,11 +153,12 @@
final List<WifiSliceItem> disconnectedWifiList = wifiList.stream()
.filter(wifiSliceItem -> wifiSliceItem.getConnectedState()
!= WifiEntry.CONNECTED_STATE_CONNECTED)
- .limit(maxListSize)
+ .limit(maxListSize - 1)
.collect(Collectors.toList());
for (WifiSliceItem item : disconnectedWifiList) {
listBuilder.addRow(getWifiSliceItemRow(item));
}
+ listBuilder.addRow(getSeeAllRow());
}
return listBuilder.build();
}
@@ -252,6 +256,31 @@
.setSubtitle(mContext.getText(R.string.to_switch_networks_disconnect_ethernet));
}
+ protected ListBuilder.RowBuilder getSeeAllRow() {
+ final CharSequence title = mContext.getText(R.string.previous_connected_see_all);
+ final IconCompat icon = getSeeAllIcon();
+ return new ListBuilder.RowBuilder()
+ .setTitleItem(icon, ListBuilder.ICON_IMAGE)
+ .setTitle(title)
+ .setPrimaryAction(getPrimaryAction(icon, title));
+ }
+
+ protected IconCompat getSeeAllIcon() {
+ final Drawable drawable = mContext.getDrawable(R.drawable.ic_arrow_forward);
+ if (drawable != null) {
+ drawable.setTint(
+ Utils.getColorAttrDefaultColor(mContext, android.R.attr.colorControlNormal));
+ return Utils.createIconWithDrawable(drawable);
+ }
+ return Utils.createIconWithDrawable(new ColorDrawable(Color.TRANSPARENT));
+ }
+
+ protected SliceAction getPrimaryAction(IconCompat icon, CharSequence title) {
+ final PendingIntent intent = PendingIntent.getActivity(mContext, 0 /* requestCode */,
+ getIntent(), PendingIntent.FLAG_IMMUTABLE /* flags */);
+ return SliceAction.createDeeplink(intent, icon, ListBuilder.ICON_IMAGE, title);
+ }
+
@Override
protected ListBuilder.RowBuilder getWifiSliceItemRow(WifiSliceItem wifiSliceItem) {
final CharSequence title = wifiSliceItem.getTitle();
diff --git a/src/com/android/settings/network/TurnOnWifiSlice.java b/src/com/android/settings/network/TurnOnWifiSlice.java
deleted file mode 100644
index 05a873f..0000000
--- a/src/com/android/settings/network/TurnOnWifiSlice.java
+++ /dev/null
@@ -1,147 +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.network;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.graphics.Color;
-import android.graphics.drawable.ColorDrawable;
-import android.graphics.drawable.Drawable;
-import android.net.Uri;
-import android.net.wifi.WifiManager;
-import android.util.Log;
-
-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 androidx.slice.core.SliceHints;
-
-import com.android.settings.R;
-import com.android.settings.Utils;
-import com.android.settings.slices.CustomSliceRegistry;
-import com.android.settings.slices.CustomSliceable;
-import com.android.settings.slices.SliceBackgroundWorker;
-import com.android.settings.slices.SliceBroadcastReceiver;
-
-/**
- * {@link CustomSliceable} for turning on Wi-Fi, used by generic clients.
- */
-public class TurnOnWifiSlice implements CustomSliceable {
-
- private static final String TAG = "TurnOnWifiSlice";
-
- private final Context mContext;
- private final WifiManager mWifiManager;
-
- public TurnOnWifiSlice(Context context) {
- mContext = context;
- mWifiManager = mContext.getSystemService(WifiManager.class);
- }
-
- private static void logd(String s) {
- Log.d(TAG, s);
- }
-
- @Override
- public Slice getSlice() {
- if (mWifiManager.isWifiEnabled()) {
- return null;
- }
- final String title = mContext.getText(R.string.turn_on_wifi).toString();
- final SliceAction primaryAction = SliceAction.create(getBroadcastIntent(mContext),
- getEndIcon(), ListBuilder.ICON_IMAGE, title);
- final ListBuilder listBuilder = new ListBuilder(mContext, getUri(), ListBuilder.INFINITY)
- .addRow(new RowBuilder()
- .setTitle(title)
- .addEndItem(getEndIcon(), SliceHints.ICON_IMAGE)
- .setPrimaryAction(primaryAction));
- return listBuilder.build();
- }
-
- @Override
- public Uri getUri() {
- return CustomSliceRegistry.TURN_ON_WIFI_SLICE_URI;
- }
-
- @Override
- public void onNotifyChange(Intent intent) {
- logd("Action: turn on Wi-Fi networks");
- mWifiManager.setWifiEnabled(true);
- }
-
- @Override
- public Intent getIntent() {
- return new Intent(getUri().toString())
- .setData(getUri())
- .setClass(mContext, SliceBroadcastReceiver.class);
- }
-
- private IconCompat getEndIcon() {
- final Drawable drawable = mContext.getDrawable(R.drawable.ic_settings_wireless);
- if (drawable == null) {
- return Utils.createIconWithDrawable(new ColorDrawable(Color.TRANSPARENT));
- }
- drawable.setTintList(Utils.getColorAttr(mContext, android.R.attr.colorAccent));
- return Utils.createIconWithDrawable(drawable);
- }
-
- @Override
- public Class getBackgroundWorkerClass() {
- return TurnOnWifiWorker.class;
- }
-
- /**
- * The Slice background worker {@link SliceBackgroundWorker} is used to listen the Wi-Fi
- * status change, and then notifies the Slice {@link Uri} to update.
- */
- public static class TurnOnWifiWorker extends SliceBackgroundWorker {
-
- private final IntentFilter mIntentFilter;
- private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(intent.getAction())) {
- notifySliceChange();
- }
- }
- };
-
- public TurnOnWifiWorker(Context context, Uri uri) {
- super(context, uri);
- mIntentFilter = new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION);
- }
-
- @Override
- protected void onSlicePinned() {
- getContext().registerReceiver(mBroadcastReceiver, mIntentFilter);
- }
-
- @Override
- protected void onSliceUnpinned() {
- getContext().unregisterReceiver(mBroadcastReceiver);
- }
-
- @Override
- public void close() {
- // Do nothing.
- }
- }
-}
diff --git a/src/com/android/settings/network/telephony/NetworkProviderWorker.java b/src/com/android/settings/network/telephony/NetworkProviderWorker.java
index 5205f52..369218b 100644
--- a/src/com/android/settings/network/telephony/NetworkProviderWorker.java
+++ b/src/com/android/settings/network/telephony/NetworkProviderWorker.java
@@ -54,7 +54,7 @@
DataConnectivityListener.Client, InternetUpdater.InternetChangeListener,
SubscriptionsChangeListener.SubscriptionsChangeListenerClient {
private static final String TAG = "NetworkProviderWorker";
- private static final int PROVIDER_MODEL_DEFAULT_EXPANDED_ROW_COUNT = 4;
+ private static final int PROVIDER_MODEL_DEFAULT_EXPANDED_ROW_COUNT = 5;
private DataContentObserver mMobileDataObserver;
private SignalStrengthListener mSignalStrengthListener;
private SubscriptionsChangeListener mSubscriptionsListener;
diff --git a/src/com/android/settings/network/telephony/ToggleSubscriptionDialogActivity.java b/src/com/android/settings/network/telephony/ToggleSubscriptionDialogActivity.java
index d3b2af6..0064e6c 100644
--- a/src/com/android/settings/network/telephony/ToggleSubscriptionDialogActivity.java
+++ b/src/com/android/settings/network/telephony/ToggleSubscriptionDialogActivity.java
@@ -326,7 +326,7 @@
DIALOG_TAG_ENABLE_DSDS_CONFIRMATION,
getString(R.string.sim_action_enable_dsds_title),
getString(R.string.sim_action_enable_dsds_text),
- getString(R.string.sim_action_continue),
+ getString(R.string.sim_action_yes),
getString(R.string.sim_action_no_thanks));
}
diff --git a/src/com/android/settings/notification/history/NotificationHistoryActivity.java b/src/com/android/settings/notification/history/NotificationHistoryActivity.java
index 2c80668..1d663fc 100644
--- a/src/com/android/settings/notification/history/NotificationHistoryActivity.java
+++ b/src/com/android/settings/notification/history/NotificationHistoryActivity.java
@@ -156,6 +156,7 @@
View recyclerView = mTodayView.findViewById(R.id.apps);
recyclerView.setClipToOutline(true);
mTodayView.setOutlineProvider(mOutlineProvider);
+ mSnoozeView.setOutlineProvider(mOutlineProvider);
// for each package, new header and recycler view
for (int i = 0, notificationsSize = notifications.size(); i < notificationsSize; i++) {
NotificationHistoryPackage nhp = notifications.get(i);
@@ -219,6 +220,11 @@
}
};
+ private void configureNotificationList(View recyclerView) {
+ recyclerView.setClipToOutline(true);
+ recyclerView.setOutlineProvider(mOutlineProvider);
+ }
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -227,9 +233,8 @@
mTodayView = findViewById(R.id.apps);
mSnoozeView = findViewById(R.id.snoozed_list);
mDismissView = findViewById(R.id.recently_dismissed_list);
- View recyclerView = mDismissView.findViewById(R.id.notification_list);
- recyclerView.setClipToOutline(true);
- recyclerView.setOutlineProvider(mOutlineProvider);
+ configureNotificationList(mDismissView.findViewById(R.id.notification_list));
+ configureNotificationList(mSnoozeView.findViewById(R.id.notification_list));
mHistoryOff = findViewById(R.id.history_off);
mHistoryOn = findViewById(R.id.history_on);
mHistoryEmpty = findViewById(R.id.history_on_empty);
diff --git a/src/com/android/settings/panel/InternetConnectivityPanel.java b/src/com/android/settings/panel/InternetConnectivityPanel.java
index a6c18a5..e6344d8 100644
--- a/src/com/android/settings/panel/InternetConnectivityPanel.java
+++ b/src/com/android/settings/panel/InternetConnectivityPanel.java
@@ -19,8 +19,6 @@
import static androidx.lifecycle.Lifecycle.Event.ON_PAUSE;
import static androidx.lifecycle.Lifecycle.Event.ON_RESUME;
-import static com.android.settings.network.NetworkProviderSettings.ACTION_NETWORK_PROVIDER_SETTINGS;
-
import android.app.settings.SettingsEnums;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -32,7 +30,6 @@
import android.os.Handler;
import android.os.HandlerExecutor;
import android.os.Looper;
-import android.provider.Settings;
import android.telephony.ServiceState;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyCallback;
@@ -41,6 +38,7 @@
import android.util.Log;
import androidx.annotation.VisibleForTesting;
+import androidx.fragment.app.FragmentActivity;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;
@@ -64,7 +62,7 @@
SubscriptionsChangeListener.SubscriptionsChangeListenerClient {
private static final String TAG = "InternetConnectivityPanel";
private static final int SUBTITLE_TEXT_NONE = -1;
- private static final int SUBTITLE_TEXT_WIFI_IS_TURNED_ON = R.string.wifi_is_turned_on_subtitle;
+ private static final int SUBTITLE_TEXT_WIFI_IS_OFF = R.string.wifi_is_off;
private static final int SUBTITLE_TEXT_TAP_A_NETWORK_TO_CONNECT =
R.string.tap_a_network_to_connect;
private static final int SUBTITLE_TEXT_SEARCHING_FOR_NETWORKS =
@@ -198,7 +196,6 @@
final List<Uri> uris = new ArrayList<>();
if (mIsProviderModelEnabled) {
uris.add(CustomSliceRegistry.PROVIDER_MODEL_SLICE_URI);
- uris.add(CustomSliceRegistry.TURN_ON_WIFI_SLICE_URI);
} else {
uris.add(CustomSliceRegistry.WIFI_SLICE_URI);
uris.add(CustomSliceRegistry.MOBILE_DATA_SLICE_URI);
@@ -209,9 +206,7 @@
@Override
public Intent getSeeMoreIntent() {
- return new Intent(mIsProviderModelEnabled
- ? ACTION_NETWORK_PROVIDER_SETTINGS : Settings.ACTION_WIRELESS_SETTINGS)
- .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ return null;
}
@Override
@@ -221,15 +216,14 @@
@Override
public CharSequence getCustomizedButtonTitle() {
- if (mInternetUpdater.isAirplaneModeOn() && !mInternetUpdater.isWifiEnabled()) {
- return null;
- }
- return mContext.getText(R.string.settings_button);
+ return mContext.getText(
+ mInternetUpdater.isWifiEnabled() ? R.string.turn_off_wifi : R.string.turn_on_wifi);
}
@Override
- public void onClickCustomizedButton() {
- mContext.startActivity(getSeeMoreIntent());
+ public void onClickCustomizedButton(FragmentActivity panelActivity) {
+ // Don't finish the panel activity
+ mWifiManager.setWifiEnabled(!mInternetUpdater.isWifiEnabled());
}
@Override
@@ -290,15 +284,7 @@
return;
}
updateSubtitleText();
-
- log("Subtitle:" + mSubtitle);
- if (mSubtitle != SUBTITLE_TEXT_NONE) {
- mCallback.onHeaderChanged();
- } else {
- // Other situations.
- // Title: Airplane mode / Internet
- mCallback.onTitleChanged();
- }
+ mCallback.onHeaderChanged();
mCallback.onCustomizedButtonStateChanged();
}
@@ -310,15 +296,23 @@
private void updateSubtitleText() {
mSubtitle = SUBTITLE_TEXT_NONE;
if (!mInternetUpdater.isWifiEnabled()) {
+ if (!mInternetUpdater.isAirplaneModeOn()) {
+ // When the airplane mode is off and Wi-Fi is disabled.
+ // Sub-Title: Wi-Fi is off
+ log("Airplane mode off + Wi-Fi off.");
+ mSubtitle = SUBTITLE_TEXT_WIFI_IS_OFF;
+ }
+ return;
+ }
+
+ if (mIsProgressBarVisible) {
+ // When the Wi-Fi scan result callback is received
+ // Sub-Title: Searching for networks...
+ mSubtitle = SUBTITLE_TEXT_SEARCHING_FOR_NETWORKS;
return;
}
if (mInternetUpdater.isAirplaneModeOn()) {
- // When the airplane mode is on and Wi-Fi is enabled.
- // Title: Airplane mode
- // Sub-Title: Wi-Fi is turned on
- log("Airplane mode is on + Wi-Fi on.");
- mSubtitle = SUBTITLE_TEXT_WIFI_IS_TURNED_ON;
return;
}
@@ -330,13 +324,6 @@
return;
}
- if (mIsProgressBarVisible) {
- // When the Wi-Fi scan result callback is received
- // Sub-Title: Searching for networks...
- mSubtitle = SUBTITLE_TEXT_SEARCHING_FOR_NETWORKS;
- return;
- }
-
// Sub-Title:
// show non_carrier_network_unavailable
// - while Wi-Fi on + no Wi-Fi item
diff --git a/src/com/android/settings/panel/PanelContent.java b/src/com/android/settings/panel/PanelContent.java
index 4c24182..6b58228 100644
--- a/src/com/android/settings/panel/PanelContent.java
+++ b/src/com/android/settings/panel/PanelContent.java
@@ -20,6 +20,7 @@
import android.net.Uri;
import androidx.core.graphics.drawable.IconCompat;
+import androidx.fragment.app.FragmentActivity;
import com.android.settingslib.core.instrumentation.Instrumentable;
@@ -94,8 +95,11 @@
/**
* Implement the click event for custom button.
+ *
+ * @param panelActivity the FragmentActivity from PanelFragment, the user can decide whether
+ * to finish activity or not.
*/
- default void onClickCustomizedButton() {}
+ default void onClickCustomizedButton(FragmentActivity panelActivity) {}
/**
* Register to start receiving callbacks for custom button events.
diff --git a/src/com/android/settings/panel/PanelFragment.java b/src/com/android/settings/panel/PanelFragment.java
index 31cb7b8..cd2bb50 100644
--- a/src/com/android/settings/panel/PanelFragment.java
+++ b/src/com/android/settings/panel/PanelFragment.java
@@ -491,11 +491,11 @@
mPanelClosedKey = PanelClosedKeys.KEY_SEE_MORE;
final FragmentActivity activity = getActivity();
if (mPanel.isCustomizedButtonUsed()) {
- mPanel.onClickCustomizedButton();
+ mPanel.onClickCustomizedButton(activity);
} else {
activity.startActivityForResult(mPanel.getSeeMoreIntent(), 0);
+ activity.finish();
}
- activity.finish();
};
}
diff --git a/src/com/android/settings/slices/CustomSliceRegistry.java b/src/com/android/settings/slices/CustomSliceRegistry.java
index 713d61a..d1b169c 100644
--- a/src/com/android/settings/slices/CustomSliceRegistry.java
+++ b/src/com/android/settings/slices/CustomSliceRegistry.java
@@ -40,7 +40,6 @@
import com.android.settings.media.MediaOutputIndicatorSlice;
import com.android.settings.media.RemoteMediaSlice;
import com.android.settings.network.ProviderModelSlice;
-import com.android.settings.network.TurnOnWifiSlice;
import com.android.settings.network.telephony.MobileDataSlice;
import com.android.settings.notification.zen.ZenModeButtonPreferenceController;
import com.android.settings.wifi.calling.WifiCallingSliceHelper;
@@ -337,7 +336,6 @@
sUriToSlice.put(DARK_THEME_SLICE_URI, DarkThemeSlice.class);
sUriToSlice.put(REMOTE_MEDIA_SLICE_URI, RemoteMediaSlice.class);
sUriToSlice.put(ALWAYS_ON_SLICE_URI, AlwaysOnDisplaySlice.class);
- sUriToSlice.put(TURN_ON_WIFI_SLICE_URI, TurnOnWifiSlice.class);
}
public static Class<? extends CustomSliceable> getSliceClassByUri(Uri uri) {
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/AddDevicePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/AddDevicePreferenceControllerTest.java
index c3841c9..7384d3a 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/AddDevicePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/AddDevicePreferenceControllerTest.java
@@ -87,7 +87,7 @@
@Test
public void addDevice_bt_resume_on_then_off() {
when(mBluetoothAdapter.isEnabled()).thenReturn(true);
- mAddDevicePreferenceController.updateState();
+ mAddDevicePreferenceController.updateState(mAddDevicePreference);
assertTrue(TextUtils.isEmpty(mAddDevicePreference.getSummary()));
Intent intent = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED);
@@ -103,7 +103,7 @@
@Test
public void addDevice_bt_resume_off_then_on() {
when(mBluetoothAdapter.isEnabled()).thenReturn(false);
- mAddDevicePreferenceController.updateState();
+ mAddDevicePreferenceController.updateState(mAddDevicePreference);
assertThat(mAddDevicePreference.getSummary()).isEqualTo(
mContext.getString(R.string.connected_device_add_device_summary));
@@ -131,9 +131,8 @@
}
@Test
- public void getAvailabilityStatus_bluetoothIsDisabled_unSupported() {
- mPackageManager.setSystemFeature(PackageManager.FEATURE_BLUETOOTH, true);
- when(mBluetoothAdapter.isEnabled()).thenReturn(false);
+ public void getAvailabilityStatus_noBluetoothFeature_unSupported() {
+ mPackageManager.setSystemFeature(PackageManager.FEATURE_BLUETOOTH, false);
assertThat(mAddDevicePreferenceController.getAvailabilityStatus())
.isEqualTo(UNSUPPORTED_ON_DEVICE);
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/AddDeviceSummaryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/AddDeviceSummaryPreferenceControllerTest.java
deleted file mode 100644
index e134a16..0000000
--- a/tests/robotests/src/com/android/settings/connecteddevice/AddDeviceSummaryPreferenceControllerTest.java
+++ /dev/null
@@ -1,151 +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.connecteddevice;
-
-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.junit.Assert.assertTrue;
-import static org.mockito.Mockito.when;
-
-import android.bluetooth.BluetoothAdapter;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.text.TextUtils;
-
-import androidx.preference.PreferenceScreen;
-
-import com.android.settings.R;
-import com.android.settingslib.RestrictedPreference;
-
-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.Shadows;
-import org.robolectric.annotation.Config;
-import org.robolectric.shadows.ShadowApplicationPackageManager;
-import org.robolectric.util.ReflectionHelpers;
-
-@RunWith(RobolectricTestRunner.class)
-@Config(shadows = ShadowApplicationPackageManager.class)
-public class AddDeviceSummaryPreferenceControllerTest {
-
- @Mock
- private PreferenceScreen mScreen;
- @Mock
- private BluetoothAdapter mBluetoothAdapter;
-
- private Context mContext;
- private AddDeviceSummaryPreferenceController mAddDeviceSummaryPreferenceController;
- private RestrictedPreference mAddDevicePreference;
- private ShadowApplicationPackageManager mPackageManager;
-
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
-
- mContext = RuntimeEnvironment.application;
- mPackageManager = (ShadowApplicationPackageManager) Shadows.shadowOf(
- mContext.getPackageManager());
- mPackageManager.setSystemFeature(PackageManager.FEATURE_BLUETOOTH, true);
-
- mAddDeviceSummaryPreferenceController = new AddDeviceSummaryPreferenceController(mContext,
- "add_bt_devices");
- ReflectionHelpers.setField(mAddDeviceSummaryPreferenceController,
- "mBluetoothAdapter", mBluetoothAdapter);
-
- String key = mAddDeviceSummaryPreferenceController.getPreferenceKey();
- mAddDevicePreference = new RestrictedPreference(mContext);
- mAddDevicePreference.setKey(key);
- when(mScreen.findPreference(key)).thenReturn(mAddDevicePreference);
- when(mBluetoothAdapter.isEnabled()).thenReturn(false);
- mAddDeviceSummaryPreferenceController.displayPreference(mScreen);
- }
-
- @Test
- public void getSummary_btOnThenOff_summaryShouldBeShown() {
- when(mBluetoothAdapter.isEnabled()).thenReturn(true);
-
- mAddDeviceSummaryPreferenceController.updateState();
-
- assertTrue(TextUtils.isEmpty(mAddDevicePreference.getSummary()));
-
- Intent intent = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED);
- intent.putExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_OFF);
- BroadcastReceiver receiver = ReflectionHelpers.getField(
- mAddDeviceSummaryPreferenceController, "mReceiver");
- when(mBluetoothAdapter.isEnabled()).thenReturn(false);
-
- receiver.onReceive(mContext, intent);
-
- assertThat(mAddDevicePreference.getSummary()).isEqualTo(
- mContext.getString(R.string.connected_device_add_device_summary));
- }
-
- @Test
- public void getSummary_btOffThenOn_summaryShouldNotBeShown() {
- when(mBluetoothAdapter.isEnabled()).thenReturn(false);
-
- mAddDeviceSummaryPreferenceController.updateState();
-
- assertThat(mAddDevicePreference.getSummary()).isEqualTo(
- mContext.getString(R.string.connected_device_add_device_summary));
-
- Intent intent = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED);
- intent.putExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_ON);
- BroadcastReceiver receiver = ReflectionHelpers.getField(
- mAddDeviceSummaryPreferenceController, "mReceiver");
- when(mBluetoothAdapter.isEnabled()).thenReturn(true);
-
- receiver.onReceive(mContext, intent);
-
- assertTrue(TextUtils.isEmpty(mAddDevicePreference.getSummary()));
- }
-
- @Test
- public void getAvailabilityStatus_notHaveBluetoothFeature_unSupported() {
- mPackageManager.setSystemFeature(PackageManager.FEATURE_BLUETOOTH, false);
-
- assertThat(mAddDeviceSummaryPreferenceController.getAvailabilityStatus())
- .isEqualTo(UNSUPPORTED_ON_DEVICE);
- }
-
- @Test
- public void getAvailabilityStatus_haveBluetoothFeature_supported() {
- mPackageManager.setSystemFeature(PackageManager.FEATURE_BLUETOOTH, true);
-
- assertThat(mAddDeviceSummaryPreferenceController.getAvailabilityStatus())
- .isEqualTo(AVAILABLE);
- }
-
- @Test
- public void getAvailabilityStatus_bluetoothIsEnabled_unSupported() {
- mPackageManager.setSystemFeature(PackageManager.FEATURE_BLUETOOTH, true);
- when(mBluetoothAdapter.isEnabled()).thenReturn(true);
-
- assertThat(mAddDeviceSummaryPreferenceController.getAvailabilityStatus())
- .isEqualTo(UNSUPPORTED_ON_DEVICE);
- }
-}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryChartPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryChartPreferenceControllerTest.java
index 9e2f65d..606dc19 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryChartPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryChartPreferenceControllerTest.java
@@ -307,6 +307,7 @@
doReturn(appLabel).when(mBatteryDiffEntry).getAppLabel();
doReturn(PREF_KEY).when(mBatteryHistEntry).getKey();
doReturn(null).when(mAppListGroup).findPreference(PREF_KEY);
+ doReturn(false).when(mBatteryDiffEntry).validForRestriction();
mBatteryChartPreferenceController.addPreferenceToScreen(
Arrays.asList(mBatteryDiffEntry));
@@ -324,6 +325,7 @@
assertThat(pref.getOrder()).isEqualTo(1);
assertThat(pref.getBatteryDiffEntry()).isSameInstanceAs(mBatteryDiffEntry);
assertThat(pref.isSingleLineTitle()).isTrue();
+ assertThat(pref.isEnabled()).isFalse();
}
@Test
@@ -353,7 +355,7 @@
}
@Test
- public void testHandlePreferenceTreeClick_validPackageName_returnTrue() {
+ public void testHandlePreferenceTreeClick_forAppEntry_returnTrue() {
doReturn(false).when(mBatteryHistEntry).isAppEntry();
doReturn(mBatteryDiffEntry).when(mPowerGaugePreference).getBatteryDiffEntry();
@@ -371,15 +373,13 @@
}
@Test
- public void testHandlePreferenceTreeClick_appEntryWithInvalidPackage_returnFalse() {
+ public void testHandlePreferenceTreeClick_forSystemEntry_returnTrue() {
mBatteryChartPreferenceController.mBatteryUtils = mBatteryUtils;
doReturn(true).when(mBatteryHistEntry).isAppEntry();
- doReturn(BatteryUtils.UID_NULL).when(mBatteryUtils)
- .getPackageUid(mBatteryHistEntry.mPackageName);
doReturn(mBatteryDiffEntry).when(mPowerGaugePreference).getBatteryDiffEntry();
assertThat(mBatteryChartPreferenceController.handlePreferenceTreeClick(
- mPowerGaugePreference)).isFalse();
+ mPowerGaugePreference)).isTrue();
verify(mMetricsFeatureProvider)
.action(
mContext,
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryDiffEntryTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryDiffEntryTest.java
index 5860163..0df53f1 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryDiffEntryTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryDiffEntryTest.java
@@ -17,12 +17,15 @@
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import android.content.ContentValues;
import android.content.Context;
import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.os.BatteryConsumer;
@@ -56,11 +59,13 @@
@Mock private Drawable mockDrawable2;
@Mock private Drawable mockBadgedDrawable;
@Mock private BatteryHistEntry mBatteryHistEntry;
+ @Mock private PackageInfo mockPackageInfo;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
+ doReturn(mContext).when(mContext).getApplicationContext();
doReturn(mockUserManager).when(mContext).getSystemService(UserManager.class);
doReturn(mockPackageManager).when(mContext).getPackageManager();
BatteryDiffEntry.clearCache();
@@ -110,6 +115,7 @@
@Test
public void testLoadLabelAndIcon_forSystemBattery_returnExpectedResult() {
+ final String expectedName = "Ambient display";
// Generates fake testing data.
final ContentValues values = getContentValuesWithType(
ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY);
@@ -119,13 +125,22 @@
final BatteryDiffEntry entry = createBatteryDiffEntry(10, batteryHistEntry);
- assertThat(entry.getAppLabel()).isEqualTo("Ambient display");
+ assertThat(entry.getAppLabel()).isEqualTo(expectedName);
assertThat(entry.getAppIconId()).isEqualTo(R.drawable.ic_settings_aod);
- assertThat(BatteryDiffEntry.sResourceCache).isEmpty();
+ assertThat(BatteryDiffEntry.sResourceCache).hasSize(1);
+ // Verifies the app label in the cache.
+ final BatteryEntry.NameAndIcon nameAndIcon =
+ BatteryDiffEntry.sResourceCache.get(entry.getKey());
+ assertThat(nameAndIcon.name).isEqualTo(expectedName);
+ assertThat(nameAndIcon.iconId).isEqualTo(R.drawable.ic_settings_aod);
+ // Verifies the restrictable flag in the cache.
+ assertThat(entry.mValidForRestriction).isTrue();
+ assertThat(BatteryDiffEntry.sValidForRestriction.get(entry.getKey())).isTrue();
}
@Test
public void testLoadLabelAndIcon_forUserBattery_returnExpectedResult() {
+ final String expectedName = "Removed user";
doReturn(null).when(mockUserManager).getUserInfo(1001);
// Generates fake testing data.
final ContentValues values = getContentValuesWithType(
@@ -135,10 +150,18 @@
final BatteryDiffEntry entry = createBatteryDiffEntry(10, batteryHistEntry);
- assertThat(entry.getAppLabel()).isEqualTo("Removed user");
+ assertThat(entry.getAppLabel()).isEqualTo(expectedName);
assertThat(entry.getAppIcon()).isNull();
assertThat(entry.getAppIconId()).isEqualTo(0);
- assertThat(BatteryDiffEntry.sResourceCache).isEmpty();
+ assertThat(BatteryDiffEntry.sResourceCache).hasSize(1);
+ // Verifies the app label in the cache.
+ final BatteryEntry.NameAndIcon nameAndIcon =
+ BatteryDiffEntry.sResourceCache.get(entry.getKey());
+ assertThat(nameAndIcon.name).isEqualTo(expectedName);
+ assertThat(nameAndIcon.iconId).isEqualTo(0);
+ // Verifies the restrictable flag in the cache.
+ assertThat(entry.mValidForRestriction).isTrue();
+ assertThat(BatteryDiffEntry.sValidForRestriction.get(entry.getKey())).isTrue();
}
@Test
@@ -162,8 +185,11 @@
assertThat(BatteryDiffEntry.sResourceCache).hasSize(1);
// Verifies the app label in the cache.
final BatteryEntry.NameAndIcon nameAndIcon =
- BatteryDiffEntry.sResourceCache.get(batteryHistEntry.getKey());
+ BatteryDiffEntry.sResourceCache.get(entry.getKey());
assertThat(nameAndIcon.name).isEqualTo(expectedAppLabel);
+ // Verifies the restrictable flag in the cache.
+ assertThat(entry.mValidForRestriction).isFalse();
+ assertThat(BatteryDiffEntry.sValidForRestriction.get(entry.getKey())).isFalse();
}
@Test
@@ -179,7 +205,7 @@
assertThat(BatteryDiffEntry.sResourceCache).hasSize(1);
// Verifies the app label in the cache.
final BatteryEntry.NameAndIcon nameAndIcon =
- BatteryDiffEntry.sResourceCache.get(batteryHistEntry.getKey());
+ BatteryDiffEntry.sResourceCache.get(entry.getKey());
assertThat(nameAndIcon.name).isEqualTo(expectedAppLabel);
}
@@ -225,11 +251,25 @@
assertThat(BatteryDiffEntry.sResourceCache).hasSize(1);
// Verifies the app label in the cache.
final BatteryEntry.NameAndIcon nameAndIcon =
- BatteryDiffEntry.sResourceCache.get(entry.mBatteryHistEntry.getKey());
+ BatteryDiffEntry.sResourceCache.get(entry.getKey());
assertThat(nameAndIcon.icon).isEqualTo(mockBadgedDrawable);
}
@Test
+ public void testClearCache_clearDataForResourcesAndFlags() {
+ BatteryDiffEntry.sResourceCache.put(
+ "fake application key",
+ new BatteryEntry.NameAndIcon("app label", null, /*iconId=*/ 0));
+ BatteryDiffEntry.sValidForRestriction.put(
+ "fake application key", Boolean.valueOf(false));
+
+ BatteryDiffEntry.clearCache();
+
+ assertThat(BatteryDiffEntry.sResourceCache).isEmpty();
+ assertThat(BatteryDiffEntry.sValidForRestriction).isEmpty();
+ }
+
+ @Test
public void testClearCache_switchLocale_clearCacheIconAndLabel() throws Exception {
final int userId = UserHandle.getUserId(1001);
doReturn(mockBadgedDrawable).when(mockUserManager)
@@ -248,7 +288,7 @@
assertThat(entry2.getAppIcon()).isEqualTo(mockDrawable2);
// Verifies the cache is updated into the new drawable.
final BatteryEntry.NameAndIcon nameAndIcon =
- BatteryDiffEntry.sResourceCache.get(entry2.mBatteryHistEntry.getKey());
+ BatteryDiffEntry.sResourceCache.get(entry2.getKey());
assertThat(nameAndIcon.icon).isEqualTo(mockDrawable2);
}
@@ -297,6 +337,40 @@
assertThat(entry.isSystemEntry()).isTrue();
}
+ @Test
+ public void testUpdateRestrictionFlagState_updateFlagAsExpected() throws Exception {
+ final String expectedAppLabel = "fake app label";
+ final String fakePackageName = "com.fake.google.com";
+ final ContentValues values = getContentValuesWithType(
+ ConvertUtils.CONSUMER_TYPE_UID_BATTERY);
+ values.put("uid", /*invalid uid*/ 10001);
+ values.put("packageName", fakePackageName);
+ final BatteryDiffEntry entry =
+ createBatteryDiffEntry(10, new BatteryHistEntry(values));
+
+ entry.updateRestrictionFlagState();
+ // Sets false if the app entry cannot be found.
+ assertThat(entry.mValidForRestriction).isFalse();
+
+ doReturn(BatteryUtils.UID_NULL).when(mockPackageManager).getPackageUid(
+ entry.getPackageName(), PackageManager.GET_META_DATA);
+ entry.updateRestrictionFlagState();
+ // Sets false if the app is invalid package name.
+ assertThat(entry.mValidForRestriction).isFalse();
+
+ doReturn(1000).when(mockPackageManager).getPackageUid(
+ entry.getPackageName(), PackageManager.GET_META_DATA);
+ entry.updateRestrictionFlagState();
+ // Sets false if the app PackageInfo cannot be found.
+ assertThat(entry.mValidForRestriction).isFalse();
+
+ doReturn(mockPackageInfo).when(mockPackageManager).getPackageInfo(
+ eq(entry.getPackageName()), anyInt());
+ entry.updateRestrictionFlagState();
+ // Sets true if package is valid and PackageInfo can be found.
+ assertThat(entry.mValidForRestriction).isTrue();
+ }
+
private BatteryDiffEntry createBatteryDiffEntry(
int consumerType, long uid, boolean isHidden) {
final ContentValues values = getContentValuesWithType(consumerType);
diff --git a/tests/unit/src/com/android/settings/applications/appinfo/HibernationSwitchPreferenceControllerTest.java b/tests/unit/src/com/android/settings/applications/appinfo/HibernationSwitchPreferenceControllerTest.java
index 65ffe4b..1e1799a 100644
--- a/tests/unit/src/com/android/settings/applications/appinfo/HibernationSwitchPreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/applications/appinfo/HibernationSwitchPreferenceControllerTest.java
@@ -22,6 +22,7 @@
import static android.provider.DeviceConfig.NAMESPACE_APP_HIBERNATION;
import static com.android.settings.Utils.PROPERTY_APP_HIBERNATION_ENABLED;
+import static com.android.settings.Utils.PROPERTY_HIBERNATION_TARGETS_PRE_S_APPS;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.google.common.truth.Truth.assertThat;
@@ -143,4 +144,18 @@
verify(mPreference).setChecked(false);
}
+
+ @Test
+ public void updateState_exemptedByDefaultPackageOverriddenByPreSFlag_shouldCheck() {
+ DeviceConfig.setProperty(NAMESPACE_APP_HIBERNATION, PROPERTY_HIBERNATION_TARGETS_PRE_S_APPS,
+ "true", true /* makeDefault */);
+ when(mAppOpsManager.unsafeCheckOpNoThrow(
+ eq(OPSTR_AUTO_REVOKE_PERMISSIONS_IF_UNUSED), anyInt(), eq(EXEMPTED_PACKAGE_NAME)))
+ .thenReturn(MODE_DEFAULT);
+ mController.setPackage(EXEMPTED_PACKAGE_NAME);
+
+ mController.updateState(mPreference);
+
+ verify(mPreference).setChecked(true);
+ }
}
diff --git a/tests/unit/src/com/android/settings/network/ProviderModelSliceTest.java b/tests/unit/src/com/android/settings/network/ProviderModelSliceTest.java
index 4b06acf..fb17e34 100644
--- a/tests/unit/src/com/android/settings/network/ProviderModelSliceTest.java
+++ b/tests/unit/src/com/android/settings/network/ProviderModelSliceTest.java
@@ -153,6 +153,7 @@
assertThat(slice).isNotNull();
verify(mListBuilder, times(1)).addRow(mMockCarrierRowBuild);
+ assertThat(mMockProviderModelSlice.hasSeeAllRow()).isFalse();
}
@Test
@@ -166,11 +167,12 @@
assertThat(slice).isNotNull();
verify(mListBuilder, times(1)).addRow(mMockCarrierRowBuild);
+ assertThat(mMockProviderModelSlice.hasSeeAllRow()).isFalse();
}
@Test
@UiThreadTest
- public void getSlice_haveTwoWifiAndOneCarrier_getCarrierAndTwoWiFi() {
+ public void getSlice_haveTwoWifiAndOneCarrier_getCarrierAndTwoWiFiAndSeeAll() {
mWifiList.clear();
mockWifiItemCondition(mMockWifiSliceItem1, "wifi1", "wifi1",
WifiEntry.CONNECTED_STATE_CONNECTED, "wifi1_key", true);
@@ -185,12 +187,13 @@
assertThat(slice).isNotNull();
verify(mListBuilder, times(1)).addRow(mMockCarrierRowBuild);
- verify(mListBuilder, times(3)).addRow(any(ListBuilder.RowBuilder.class));
+ verify(mListBuilder, times(4)).addRow(any(ListBuilder.RowBuilder.class));
+ assertThat(mMockProviderModelSlice.hasSeeAllRow()).isTrue();
}
@Test
@UiThreadTest
- public void getSlice_haveOneConnectedWifiAndTwoDisconnectedWifiAndNoCarrier_getTwoRow() {
+ public void getSlice_haveOneConnectedWifiAndTwoDisconnectedWifiAndNoCarrier_getFourRow() {
mWifiList.clear();
mockWifiItemCondition(mMockWifiSliceItem1, "wifi1", "wifi1",
WifiEntry.CONNECTED_STATE_CONNECTED, "wifi1_key", true);
@@ -207,12 +210,13 @@
final Slice slice = mMockProviderModelSlice.getSlice();
assertThat(slice).isNotNull();
- verify(mListBuilder, times(3)).addRow(any(ListBuilder.RowBuilder.class));
+ verify(mListBuilder, times(4)).addRow(any(ListBuilder.RowBuilder.class));
+ assertThat(mMockProviderModelSlice.hasSeeAllRow()).isTrue();
}
@Test
@UiThreadTest
- public void getSlice_haveTwoDisconnectedWifiAndNoCarrier_getTwoRow() {
+ public void getSlice_haveTwoDisconnectedWifiAndNoCarrier_getThreeRow() {
mWifiList.clear();
mockWifiItemCondition(mMockWifiSliceItem1, "wifi1", "wifi1",
WifiEntry.CONNECTED_STATE_DISCONNECTED, "wifi1_key", true);
@@ -226,12 +230,13 @@
final Slice slice = mMockProviderModelSlice.getSlice();
assertThat(slice).isNotNull();
- verify(mListBuilder, times(2)).addRow(any(ListBuilder.RowBuilder.class));
+ verify(mListBuilder, times(3)).addRow(any(ListBuilder.RowBuilder.class));
+ assertThat(mMockProviderModelSlice.hasSeeAllRow()).isTrue();
}
@Test
@UiThreadTest
- public void getSlice_haveEthernetAndCarrierAndTwoDisconnectedWifi_getFourRow() {
+ public void getSlice_haveEthernetAndCarrierAndTwoDisconnectedWifi_getFiveRow() {
mWifiList.clear();
mockWifiItemCondition(mMockWifiSliceItem1, "wifi1", "wifi1",
WifiEntry.CONNECTED_STATE_DISCONNECTED, "wifi1_key", true);
@@ -249,12 +254,13 @@
assertThat(slice).isNotNull();
assertThat(mMockProviderModelSlice.hasCreateEthernetRow()).isTrue();
verify(mListBuilder, times(1)).addRow(mMockCarrierRowBuild);
- verify(mListBuilder, times(4)).addRow(any(ListBuilder.RowBuilder.class));
+ verify(mListBuilder, times(5)).addRow(any(ListBuilder.RowBuilder.class));
+ assertThat(mMockProviderModelSlice.hasSeeAllRow()).isTrue();
}
@Test
@UiThreadTest
- public void getSlice_haveEthernetAndCarrierAndConnectedWifiAndDisconnectedWifi_getFourRow() {
+ public void getSlice_haveEthernetAndCarrierAndConnectedWifiAndDisconnectedWifi_getFiveRow() {
mWifiList.clear();
mockWifiItemCondition(mMockWifiSliceItem1, "wifi1", "wifi1",
WifiEntry.CONNECTED_STATE_CONNECTED, "wifi1_key", true);
@@ -272,7 +278,8 @@
assertThat(slice).isNotNull();
assertThat(mMockProviderModelSlice.hasCreateEthernetRow()).isTrue();
verify(mListBuilder, times(1)).addRow(mMockCarrierRowBuild);
- verify(mListBuilder, times(4)).addRow(any(ListBuilder.RowBuilder.class));
+ verify(mListBuilder, times(5)).addRow(any(ListBuilder.RowBuilder.class));
+ assertThat(mMockProviderModelSlice.hasSeeAllRow()).isTrue();
}
@Test
@@ -334,6 +341,7 @@
public class MockProviderModelSlice extends ProviderModelSlice {
private MockNetworkProviderWorker mNetworkProviderWorker;
private boolean mHasCreateEthernetRow;
+ private boolean mHasSeeAllRow;
MockProviderModelSlice(Context context, MockNetworkProviderWorker networkProviderWorker) {
super(context);
@@ -356,9 +364,19 @@
return super.createEthernetRow();
}
+ @Override
+ protected ListBuilder.RowBuilder getSeeAllRow() {
+ mHasSeeAllRow = true;
+ return super.getSeeAllRow();
+ }
+
public boolean hasCreateEthernetRow() {
return mHasCreateEthernetRow;
}
+
+ public boolean hasSeeAllRow() {
+ return mHasSeeAllRow;
+ }
}
@Test
diff --git a/tests/unit/src/com/android/settings/network/TurnOnWifiSliceTest.java b/tests/unit/src/com/android/settings/network/TurnOnWifiSliceTest.java
deleted file mode 100644
index befa655..0000000
--- a/tests/unit/src/com/android/settings/network/TurnOnWifiSliceTest.java
+++ /dev/null
@@ -1,85 +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.network;
-
-import static com.google.common.truth.Truth.assertThat;
-
-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.Intent;
-import android.net.wifi.WifiManager;
-
-import androidx.slice.SliceProvider;
-import androidx.slice.widget.SliceLiveData;
-import androidx.test.core.app.ApplicationProvider;
-import androidx.test.ext.junit.runners.AndroidJUnit4;
-
-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;
-
-@RunWith(AndroidJUnit4.class)
-public class TurnOnWifiSliceTest {
-
- @Rule
- public MockitoRule mMocks = MockitoJUnit.rule();
- @Mock
- private WifiManager mWifiManager;
-
- private Context mContext;
- private TurnOnWifiSlice mSlice;
-
- @Before
- public void setUp() {
- mContext = spy(ApplicationProvider.getApplicationContext());
- when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
-
- // Set-up specs for SliceMetadata.
- SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
- mSlice = new TurnOnWifiSlice(mContext);
- }
-
- @Test
- public void getSlice_wifiEnabled_shouldBeNull() {
- when(mWifiManager.isWifiEnabled()).thenReturn(true);
-
- assertThat(mSlice.getSlice()).isNull();
- }
-
- @Test
- public void getSlice_wifiDisabled_shouldBeNotNull() {
- when(mWifiManager.isWifiEnabled()).thenReturn(false);
-
- assertThat(mSlice.getSlice()).isNotNull();
- }
-
- @Test
- public void onNotifyChange_shouldSetWifiEnabled() {
- Intent intent = mSlice.getIntent();
-
- mSlice.onNotifyChange(intent);
-
- verify(mWifiManager).setWifiEnabled(true);
- }
-}
diff --git a/tests/unit/src/com/android/settings/panel/InternetConnectivityPanelTest.java b/tests/unit/src/com/android/settings/panel/InternetConnectivityPanelTest.java
index 150c99e..e475e6f 100644
--- a/tests/unit/src/com/android/settings/panel/InternetConnectivityPanelTest.java
+++ b/tests/unit/src/com/android/settings/panel/InternetConnectivityPanelTest.java
@@ -34,6 +34,7 @@
import android.net.wifi.WifiManager;
import android.os.Handler;
+import androidx.fragment.app.FragmentActivity;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -61,19 +62,22 @@
ApplicationProvider.getApplicationContext(), "provider_internet_settings");
public static final String TITLE_APM = ResourcesUtils.getResourcesString(
ApplicationProvider.getApplicationContext(), "airplane_mode");
- public static final String SUBTITLE_WIFI_IS_TURNED_ON = ResourcesUtils.getResourcesString(
- ApplicationProvider.getApplicationContext(), "wifi_is_turned_on_subtitle");
+ public static final String SUBTITLE_TEXT_WIFI_IS_OFF =
+ ResourcesUtils.getResourcesString(ApplicationProvider.getApplicationContext(),
+ "wifi_is_off");
public static final String SUBTITLE_TEXT_TAP_A_NETWORK_TO_CONNECT =
ResourcesUtils.getResourcesString(ApplicationProvider.getApplicationContext(),
"tap_a_network_to_connect");
- public static final String BUTTON_SETTINGS = ResourcesUtils.getResourcesString(
- ApplicationProvider.getApplicationContext(), "settings_button");
public static final String SUBTITLE_NON_CARRIER_NETWORK_UNAVAILABLE =
ResourcesUtils.getResourcesString(ApplicationProvider.getApplicationContext(),
"non_carrier_network_unavailable");
public static final String SUBTITLE_ALL_NETWORK_UNAVAILABLE =
ResourcesUtils.getResourcesString(ApplicationProvider.getApplicationContext(),
"all_network_unavailable");
+ public static final String BUTTON_TURN_ON_WIFI = ResourcesUtils.getResourcesString(
+ ApplicationProvider.getApplicationContext(), "turn_on_wifi");
+ public static final String BUTTON_TURN_OFF_WIFI = ResourcesUtils.getResourcesString(
+ ApplicationProvider.getApplicationContext(), "turn_off_wifi");
@Rule
public final MockitoRule mMocks = MockitoJUnit.rule();
@@ -87,6 +91,8 @@
private WifiManager mWifiManager;
@Mock
private ProviderModelSliceHelper mProviderModelSliceHelper;
+ @Mock
+ private FragmentActivity mPanelActivity;
private Context mContext;
private InternetConnectivityPanel mPanel;
@@ -128,13 +134,21 @@
}
@Test
- public void getSubTitle_apmOnWifiOn_shouldWifiIsTurnedOn() {
+ public void getSubTitle_apmOnWifiOn_shouldBeNull() {
doReturn(true).when(mInternetUpdater).isAirplaneModeOn();
doReturn(true).when(mInternetUpdater).isWifiEnabled();
+ assertThat(mPanel.getSubTitle()).isNull();
+ }
+
+ @Test
+ public void getSubTitle_apmOffWifiOff_wifiIsOn() {
+ doReturn(false).when(mInternetUpdater).isAirplaneModeOn();
+ doReturn(false).when(mInternetUpdater).isWifiEnabled();
+
mPanel.updatePanelTitle();
- assertThat(mPanel.getSubTitle()).isEqualTo(SUBTITLE_WIFI_IS_TURNED_ON);
+ assertThat(mPanel.getSubTitle()).isEqualTo(SUBTITLE_TEXT_WIFI_IS_OFF);
}
@Test
@@ -190,26 +204,17 @@
}
@Test
- public void getCustomizedButtonTitle_apmOff_shouldBeSettings() {
- doReturn(false).when(mInternetUpdater).isAirplaneModeOn();
-
- assertThat(mPanel.getCustomizedButtonTitle()).isEqualTo(BUTTON_SETTINGS);
- }
-
- @Test
- public void getCustomizedButtonTitle_apmOnWifiOff_shouldBeNull() {
- doReturn(true).when(mInternetUpdater).isAirplaneModeOn();
+ public void getCustomizedButtonTitle_wifiOff_turnOnWifi() {
doReturn(false).when(mInternetUpdater).isWifiEnabled();
- assertThat(mPanel.getCustomizedButtonTitle()).isNull();
+ assertThat(mPanel.getCustomizedButtonTitle()).isEqualTo(BUTTON_TURN_ON_WIFI);
}
@Test
- public void getCustomizedButtonTitle_apmOnWifiOn_shouldBeSettings() {
- doReturn(true).when(mInternetUpdater).isAirplaneModeOn();
+ public void getCustomizedButtonTitle_wifiOn_turnOffWifi() {
doReturn(true).when(mInternetUpdater).isWifiEnabled();
- assertThat(mPanel.getCustomizedButtonTitle()).isEqualTo(BUTTON_SETTINGS);
+ assertThat(mPanel.getCustomizedButtonTitle()).isEqualTo(BUTTON_TURN_OFF_WIFI);
}
@Test
@@ -227,92 +232,60 @@
public void getSlices_providerModelEnabled_containsNecessarySlices() {
List<Uri> uris = mPanel.getSlices();
- assertThat(uris).containsExactly(
- CustomSliceRegistry.PROVIDER_MODEL_SLICE_URI,
- CustomSliceRegistry.TURN_ON_WIFI_SLICE_URI);
+ assertThat(uris).containsExactly(CustomSliceRegistry.PROVIDER_MODEL_SLICE_URI);
}
@Test
- public void getSeeMoreIntent_notNull() {
- assertThat(mPanel.getSeeMoreIntent()).isNotNull();
+ public void getSeeMoreIntent_shouldBeNull() {
+ assertThat(mPanel.getSeeMoreIntent()).isNull();
}
@Test
- public void onAirplaneModeOn_apmOff_onTitleChanged() {
- doReturn(false).when(mInternetUpdater).isAirplaneModeOn();
- clearInvocations(mPanelContentCallback);
-
- mPanel.onAirplaneModeChanged(false);
-
- verify(mPanelContentCallback).onTitleChanged();
- }
-
- @Test
- public void onAirplaneModeOn_apmOnWifiOff_onTitleChanged() {
- doReturn(true).when(mInternetUpdater).isAirplaneModeOn();
- doReturn(false).when(mInternetUpdater).isWifiEnabled();
- clearInvocations(mPanelContentCallback);
-
- mPanel.onAirplaneModeChanged(true);
-
- verify(mPanelContentCallback).onTitleChanged();
- }
-
- @Test
- public void onAirplaneModeOn_apmOnWifiOn_onHeaderChanged() {
- doReturn(true).when(mInternetUpdater).isAirplaneModeOn();
+ public void onClickCustomizedButton_wifiOn_setWifiOff() {
doReturn(true).when(mInternetUpdater).isWifiEnabled();
+
+ mPanel.onClickCustomizedButton(mPanelActivity);
+
+ verify(mWifiManager).setWifiEnabled(false);
+ }
+
+ @Test
+ public void onClickCustomizedButton_wifiOff_setWifiOn() {
+ doReturn(false).when(mInternetUpdater).isWifiEnabled();
+
+ mPanel.onClickCustomizedButton(mPanelActivity);
+
+ verify(mWifiManager).setWifiEnabled(true);
+ }
+
+ @Test
+ public void onClickCustomizedButton_shouldNotFinishActivity() {
+ mPanel.onClickCustomizedButton(mPanelActivity);
+
+ verify(mPanelActivity, never()).finish();
+ }
+
+ @Test
+ public void updatePanelTitle_onHeaderChanged() {
clearInvocations(mPanelContentCallback);
- mPanel.onAirplaneModeChanged(true);
+ mPanel.updatePanelTitle();
verify(mPanelContentCallback).onHeaderChanged();
}
@Test
- public void onAirplaneModeOn_onCustomizedButtonStateChanged() {
- doReturn(true).when(mInternetUpdater).isAirplaneModeOn();
+ public void onWifiEnabledChanged_wifiOff_onCustomizedButtonStateChanged() {
+ doReturn(false).when(mInternetUpdater).isWifiEnabled();
clearInvocations(mPanelContentCallback);
- mPanel.onAirplaneModeChanged(true);
+ mPanel.onWifiEnabledChanged(false);
verify(mPanelContentCallback).onCustomizedButtonStateChanged();
}
@Test
- public void onWifiEnabledChanged_apmOff_onTitleChanged() {
- doReturn(false).when(mInternetUpdater).isAirplaneModeOn();
- clearInvocations(mPanelContentCallback);
-
- mPanel.onWifiEnabledChanged(false);
-
- verify(mPanelContentCallback).onTitleChanged();
- }
-
- @Test
- public void onWifiEnabledChanged_apmOnWifiOff_onTitleChanged() {
- doReturn(true).when(mInternetUpdater).isAirplaneModeOn();
- doReturn(false).when(mInternetUpdater).isWifiEnabled();
- clearInvocations(mPanelContentCallback);
-
- mPanel.onWifiEnabledChanged(true);
-
- verify(mPanelContentCallback).onTitleChanged();
- }
-
- @Test
- public void onWifiEnabledChanged_apmOnWifiOn_onHeaderChanged() {
- doReturn(true).when(mInternetUpdater).isAirplaneModeOn();
- doReturn(true).when(mInternetUpdater).isWifiEnabled();
- clearInvocations(mPanelContentCallback);
-
- mPanel.onWifiEnabledChanged(true);
-
- verify(mPanelContentCallback).onHeaderChanged();
- }
-
- @Test
- public void onWifiEnabledChanged_onCustomizedButtonStateChanged() {
+ public void onWifiEnabledChanged_wifiOn_onCustomizedButtonStateChanged() {
doReturn(true).when(mInternetUpdater).isWifiEnabled();
clearInvocations(mPanelContentCallback);