Snap for 7280565 from ea4ab07b63 to sc-v2-release

Change-Id: I4bd4cbba28764faa3541ba43428dd791ba8d4bba
This commit is contained in:
android-build-team Robot
2021-04-14 01:08:28 +00:00
24 changed files with 602 additions and 54 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 KiB

View File

@@ -27,7 +27,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="400dp" android:layout_height="400dp"
android:layout_weight="1" android:layout_weight="1"
android:background="?android:attr/colorBackgroundFloating" android:background="?android:attr/colorBackground"
android:contentDescription="@string/preview_pager_content_description" /> android:contentDescription="@string/preview_pager_content_description" />
<TextView <TextView

View File

@@ -29,7 +29,7 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?android:attr/colorBackgroundFloating" android:background="?android:attr/colorBackground"
android:paddingTop="@dimen/conversation_message_list_padding" android:paddingTop="@dimen/conversation_message_list_padding"
android:paddingStart="@dimen/conversation_message_list_padding" android:paddingStart="@dimen/conversation_message_list_padding"
android:paddingEnd="@dimen/conversation_message_list_padding" android:paddingEnd="@dimen/conversation_message_list_padding"

View File

@@ -19,7 +19,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:fillViewport="true" android:fillViewport="true"
android:background="?android:attr/colorBackgroundFloating" android:background="?android:attr/colorBackground"
android:importantForAccessibility="noHideDescendants"> android:importantForAccessibility="noHideDescendants">
<view class="com.android.settings.TouchBlockingFrameLayout" <view class="com.android.settings.TouchBlockingFrameLayout"

View File

@@ -20,24 +20,29 @@
android:id="@+id/content_parent" android:id="@+id/content_parent"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:transitionGroup="true"> android:fitsSystemWindows="true">
<com.google.android.material.appbar.AppBarLayout <com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar" android:id="@+id/app_bar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="180dp" android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:outlineAmbientShadowColor="@android:color/transparent"
android:outlineSpotShadowColor="@android:color/transparent"
android:background="?android:attr/colorPrimary"
android:theme="@style/Theme.CollapsingToolbar.Settings"> android:theme="@style/Theme.CollapsingToolbar.Settings">
<com.google.android.material.appbar.CollapsingToolbarLayout <com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar" android:id="@+id/collapsing_toolbar"
android:background="?android:attr/colorPrimary"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="226dp"
app:maxLines="3" app:maxLines="3"
app:contentScrim="?android:attr/colorPrimary" app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
app:scrimAnimationDuration="150"
app:scrimVisibleHeightTrigger="174dp"
app:statusBarScrim="@empty"
app:titleCollapseMode="fade"
app:collapsedTitleTextAppearance="@style/ToolbarText.Collapsed" app:collapsedTitleTextAppearance="@style/ToolbarText.Collapsed"
app:statusBarScrim="?android:attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:expandedTitleMarginStart="18dp" app:expandedTitleMarginStart="18dp"
app:expandedTitleMarginEnd="16dp" app:expandedTitleMarginEnd="16dp"
app:toolbarId="@id/action_bar"> app:toolbarId="@id/action_bar">

View File

@@ -45,8 +45,9 @@
<item name="colorPrimary">@*android:color/edge_effect_device_default_dark</item> <item name="colorPrimary">@*android:color/edge_effect_device_default_dark</item>
</style> </style>
<style name="Theme.CollapsingToolbar.Settings" <style name="Theme.CollapsingToolbar.Settings" parent="@style/Theme.MaterialComponents.DayNight">
parent="@style/Theme.MaterialComponents.DayNight"> <item name="elevationOverlayEnabled">true</item>
<item name="elevationOverlayColor">?attr/colorPrimary</item>
<item name="colorPrimary">@*android:color/primary_dark_device_default_settings</item> <item name="colorPrimary">@*android:color/primary_dark_device_default_settings</item>
<item name="colorAccent">@*android:color/accent_device_default_dark</item> <item name="colorAccent">@*android:color/accent_device_default_dark</item>
</style> </style>

View File

@@ -5890,6 +5890,21 @@
<!-- Dialog message when app can't been restricted because it is not optimized [CHAR_LIMIT=120] --> <!-- Dialog message when app can't been restricted because it is not optimized [CHAR_LIMIT=120] -->
<string name="background_activity_disabled_dialog_text">Since this app is not set to optimize battery, you can\u2019t restrict it.\n\nTo restrict the app, first turn on battery optimization.</string> <string name="background_activity_disabled_dialog_text">Since this app is not set to optimize battery, you can\u2019t restrict it.\n\nTo restrict the app, first turn on battery optimization.</string>
<!-- Title for the battery unrestricted settings [CHAR_LIMIT=40] -->
<string name="manager_battery_usage_unrestricted_title">Unrestricted</string>
<!-- Title for the battery optimized settings [CHAR_LIMIT=40] -->
<string name="manager_battery_usage_optimized_title">Optimized</string>
<!-- Summary for the battery unrestricted settings [CHAR_LIMIT=NONE] -->
<string name="manager_battery_usage_unrestricted_summary">Allow battery usage in background without restrictions. May use more battery.</string>
<!-- Summary for the battery optimized settings [CHAR_LIMIT=NONE] -->
<string name="manager_battery_usage_optimized_summary">Optimize based on your usage. Recommended for most apps.</string>
<!-- Summary for the battery restricted settings [CHAR_LIMIT=NONE] -->
<string name="manager_battery_usage_restricted_summary">Restrict battery usage while in background. App may not work as expected. Notifications may be delayed.</string>
<!-- Footer for the manage battery usage page [CHAR_LIMIT=NONE] -->
<string name="manager_battery_usage_footer">Changing how an app uses your battery can affect its performance.</string>
<!-- Footer for the manage battery usage page when app is limited to specific option (e.g This app requires restricted battery usage) [CHAR_LIMIT=NONE] -->
<string name="manager_battery_usage_footer_limited">This app requires <xliff:g id="state" example="restricted">%1$s</xliff:g> battery usage.</string>
<!-- Title for the screen usage in power use UI [CHAR_LIMIT=60] --> <!-- Title for the screen usage in power use UI [CHAR_LIMIT=60] -->
<string name="device_screen_usage">Screen usage since full charge</string> <string name="device_screen_usage">Screen usage since full charge</string>
<!-- Label for list of apps using battery in power use UI. Note: ^1 should be used in all translations[CHAR_LIMIT=120] --> <!-- Label for list of apps using battery in power use UI. Note: ^1 should be used in all translations[CHAR_LIMIT=120] -->
@@ -6298,6 +6313,8 @@
<string name ="battery_detail_info_title">Since full charge</string> <string name ="battery_detail_info_title">Since full charge</string>
<!-- Title for the battery management group [CHAR LIMIT=40] --> <!-- Title for the battery management group [CHAR LIMIT=40] -->
<string name ="battery_detail_manage_title">Manage battery usage</string> <string name ="battery_detail_manage_title">Manage battery usage</string>
<!-- Description for battery total and background usage time for an app, i.e. 1 hr 15 min total • 39 min background for past 24 hr. Note: ^1 and ^2 should be used in all translations [CHAR LIMIT=120] -->
<string name="battery_total_and_background_usage"><xliff:g id="time" example="1 hr 15 min">^1</xliff:g> total • <xliff:g id="time" example="39 min">^2</xliff:g> background for past 24 hr</string>
<!-- Graph subtext displayed to user when enhanced battery estimate is being used [CHAR LIMIT=120] --> <!-- Graph subtext displayed to user when enhanced battery estimate is being used [CHAR LIMIT=120] -->
<string name="advanced_battery_graph_subtext">Battery left estimate is based on your device usage</string> <string name="advanced_battery_graph_subtext">Battery left estimate is based on your device usage</string>
@@ -13103,17 +13120,17 @@
<string name="apps_dashboard_title">Apps</string> <string name="apps_dashboard_title">Apps</string>
<!-- Bluetooth message permission alert for notification content [CHAR LIMIT=none] --> <!-- Bluetooth message permission alert for notification content [CHAR LIMIT=none] -->
<string name="bluetooth_message_access_notification_content">Untrusted device wants to access your messages. Tap for details.</string> <string name="bluetooth_message_access_notification_content">A device wants to access your messages. Tap for details.</string>
<!-- Bluetooth message permission alert for dialog title [CHAR LIMIT=none] --> <!-- Bluetooth message permission alert for dialog title [CHAR LIMIT=none] -->
<string name="bluetooth_message_access_dialog_title">Allow access to messages?</string> <string name="bluetooth_message_access_dialog_title">Allow access to messages?</string>
<!-- Bluetooth message permission alert for dialog content [CHAR LIMIT=none] --> <!-- Bluetooth message permission alert for dialog content [CHAR LIMIT=none] -->
<string name="bluetooth_message_access_dialog_content">An untrusted Bluetooth device, <xliff:g id="device_name" example="My device">%1$s</xliff:g>, wants to access your messages.\n\nYou haven\u2019t connected to <xliff:g id="device_name" example="My device">%2$s</xliff:g> before.</string> <string name="bluetooth_message_access_dialog_content">A Bluetooth device, <xliff:g id="device_name" example="My device">%1$s</xliff:g>, wants to access your messages.\n\nYou haven\u2019t connected to <xliff:g id="device_name" example="My device">%2$s</xliff:g> before.</string>
<!-- Bluetooth phonebook permission alert for notification content [CHAR LIMIT=none] --> <!-- Bluetooth phonebook permission alert for notification content [CHAR LIMIT=none] -->
<string name="bluetooth_phonebook_access_notification_content">Untrusted device wants to access your contacts and call log. Tap for details.</string> <string name="bluetooth_phonebook_access_notification_content">A device wants to access your contacts and call log. Tap for details.</string>
<!-- Bluetooth phonebook permission alert for dialog title [CHAR LIMIT=none] --> <!-- Bluetooth phonebook permission alert for dialog title [CHAR LIMIT=none] -->
<string name="bluetooth_phonebook_access_dialog_title">Allow access to contacts and call log?</string> <string name="bluetooth_phonebook_access_dialog_title">Allow access to contacts and call log?</string>
<!-- Bluetooth phonebook permission alert for dialog content [CHAR LIMIT=none] --> <!-- Bluetooth phonebook permission alert for dialog content [CHAR LIMIT=none] -->
<string name="bluetooth_phonebook_access_dialog_content">An untrusted Bluetooth device, <xliff:g id="device_name" example="My device">%1$s</xliff:g>, wants to access your contacts and call log. This includes data about incoming and outgoing calls.\n\nYou haven\u2019t connected to <xliff:g id="device_name" example="My device">%2$s</xliff:g> before.</string> <string name="bluetooth_phonebook_access_dialog_content">A Bluetooth device, <xliff:g id="device_name" example="My device">%1$s</xliff:g>, wants to access your contacts and call log. This includes data about incoming and outgoing calls.\n\nYou haven\u2019t connected to <xliff:g id="device_name" example="My device">%2$s</xliff:g> before.</string>
<!-- Brightness category name in Display Settings [CHAR LIMIT=none] --> <!-- Brightness category name in Display Settings [CHAR LIMIT=none] -->
<string name="category_name_brightness">Brightness</string> <string name="category_name_brightness">Brightness</string>
@@ -13211,4 +13228,7 @@
<!-- All apps screen title, entry name on Apps page for the user to go to the all apps page. [CHAR LIMIT=30] --> <!-- All apps screen title, entry name on Apps page for the user to go to the all apps page. [CHAR LIMIT=30] -->
<string name="all_apps">All apps</string> <string name="all_apps">All apps</string>
<!-- Label for button to not allow grant the permission for remote devices. [CHAR_LIMIT=50] -->
<string name="request_manage_bluetooth_permission_dont_allow">Don\u2019t allow</string>
</resources> </resources>

View File

@@ -74,6 +74,8 @@
<item name="android:actionBarStyle">@style/Widget.ActionBar.SubSettings</item> <item name="android:actionBarStyle">@style/Widget.ActionBar.SubSettings</item>
<item name="switchBarTheme">@style/ThemeOverlay.SwitchBar.Settings</item> <item name="switchBarTheme">@style/ThemeOverlay.SwitchBar.Settings</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style> </style>
<style name="Theme.SubSettings" parent="Theme.SubSettings.Base"/> <style name="Theme.SubSettings" parent="Theme.SubSettings.Base"/>
@@ -272,8 +274,9 @@
<item name="colorPrimary">@*android:color/edge_effect_device_default_light</item> <item name="colorPrimary">@*android:color/edge_effect_device_default_light</item>
</style> </style>
<style name="Theme.CollapsingToolbar.Settings" <style name="Theme.CollapsingToolbar.Settings" parent="@style/Theme.MaterialComponents.DayNight">
parent="@style/Theme.MaterialComponents.DayNight"> <item name="elevationOverlayEnabled">true</item>
<item name="elevationOverlayColor">?attr/colorPrimary</item>
<item name="colorPrimary">@*android:color/primary_device_default_settings_light</item> <item name="colorPrimary">@*android:color/primary_device_default_settings_light</item>
<item name="colorAccent">@*android:color/accent_device_default_light</item> <item name="colorAccent">@*android:color/accent_device_default_light</item>
</style> </style>

View File

@@ -52,6 +52,10 @@
android:layout="@layout/preference_category_no_label" android:layout="@layout/preference_category_no_label"
settings:controller="com.android.settings.network.NetworkMobileProviderController"/> settings:controller="com.android.settings.network.NetworkMobileProviderController"/>
<PreferenceCategory
android:key="first_access_points"
android:layout="@layout/preference_category_no_label"/>
<PreferenceCategory <PreferenceCategory
android:key="access_points" android:key="access_points"
android:layout="@layout/preference_category_no_label"/> android:layout="@layout/preference_category_no_label"/>

View File

@@ -20,6 +20,7 @@ import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
import static com.android.settings.accessibility.AccessibilityUtil.State.ON; import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
import android.app.settings.SettingsEnums; import android.app.settings.SettingsEnums;
import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.hardware.display.ColorDisplayManager; import android.hardware.display.ColorDisplayManager;
import android.net.Uri; import android.net.Uri;
@@ -61,7 +62,10 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
// TODO(b/170973645): Add banner mImageUri = new Uri.Builder().scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
.authority(getPrefContext().getPackageName())
.appendPath(String.valueOf(R.drawable.extra_dim_banner))
.build();
mComponentName = AccessibilityShortcutController.REDUCE_BRIGHT_COLORS_COMPONENT_NAME; mComponentName = AccessibilityShortcutController.REDUCE_BRIGHT_COLORS_COMPONENT_NAME;
mPackageName = getText(R.string.reduce_bright_colors_preference_title); mPackageName = getText(R.string.reduce_bright_colors_preference_title);
mHtmlDescription = getText(R.string.reduce_bright_colors_preference_subtitle); mHtmlDescription = getText(R.string.reduce_bright_colors_preference_subtitle);

View File

@@ -44,6 +44,7 @@ import com.android.settingslib.utils.ThreadUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.SortedSet;
/** A customized {@link InstrumentedDialogFragment} with a progress bar. */ /** A customized {@link InstrumentedDialogFragment} with a progress bar. */
public class ProgressDialogFragment extends InstrumentedDialogFragment { public class ProgressDialogFragment extends InstrumentedDialogFragment {
@@ -146,9 +147,9 @@ public class ProgressDialogFragment extends InstrumentedDialogFragment {
int index = 0; int index = 0;
mSupportedLinkWrapperList = new ArrayList<>(); mSupportedLinkWrapperList = new ArrayList<>();
for (String host : links) { for (String host : links) {
final List<DomainOwner> ownerList = final SortedSet<DomainOwner> ownerSet =
mDomainVerificationManager.getOwnersForDomain(host); mDomainVerificationManager.getOwnersForDomain(host);
mSupportedLinkWrapperList.add(new SupportedLinkWrapper(getActivity(), host, ownerList)); mSupportedLinkWrapperList.add(new SupportedLinkWrapper(getActivity(), host, ownerSet));
index++; index++;
// The cancel was clicked while progressing to collect data. // The cancel was clicked while progressing to collect data.
if (!mProgressAlertDialog.isShowing()) { if (!mProgressAlertDialog.isShowing()) {
@@ -167,7 +168,7 @@ public class ProgressDialogFragment extends InstrumentedDialogFragment {
mProgressAlertDialog.getProgressBar().setProgress(progress); mProgressAlertDialog.getProgressBar().setProgress(progress);
} }
}); });
if (ownerList.size() == 0) { if (ownerSet.size() == 0) {
SystemClock.sleep(PROGRESS_BAR_STEPPING_TIME); SystemClock.sleep(PROGRESS_BAR_STEPPING_TIME);
} }
} }

View File

@@ -24,6 +24,7 @@ import android.util.Log;
import com.android.settings.R; import com.android.settings.R;
import java.util.List; import java.util.List;
import java.util.SortedSet;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@@ -34,14 +35,14 @@ public class SupportedLinkWrapper implements Comparable {
private static final String TAG = "SupportedLinkWrapper"; private static final String TAG = "SupportedLinkWrapper";
private String mHost; private String mHost;
private List<DomainOwner> mOwnerList; private SortedSet<DomainOwner> mOwnerSet;
private boolean mIsEnabled; private boolean mIsEnabled;
private String mLastOwnerName; private String mLastOwnerName;
private boolean mIsChecked; private boolean mIsChecked;
public SupportedLinkWrapper(Context context, String host, List<DomainOwner> ownerList) { public SupportedLinkWrapper(Context context, String host, SortedSet<DomainOwner> ownerSet) {
mHost = host; mHost = host;
mOwnerList = ownerList; mOwnerSet = ownerSet;
mIsEnabled = true; mIsEnabled = true;
mLastOwnerName = ""; mLastOwnerName = "";
mIsChecked = false; mIsChecked = false;
@@ -49,8 +50,8 @@ public class SupportedLinkWrapper implements Comparable {
} }
private void init(Context context) { private void init(Context context) {
if (mOwnerList.size() > 0) { if (mOwnerSet.size() > 0) {
final long nonOverirideableNo = mOwnerList.stream() final long nonOverirideableNo = mOwnerSet.stream()
.filter(it -> !it.isOverrideable()) .filter(it -> !it.isOverrideable())
.count(); .count();
mIsEnabled = (nonOverirideableNo == 0L); mIsEnabled = (nonOverirideableNo == 0L);
@@ -63,7 +64,7 @@ public class SupportedLinkWrapper implements Comparable {
} }
private String getLastPackageLabel(Context context, boolean isOverrideable) { private String getLastPackageLabel(Context context, boolean isOverrideable) {
final List<String> labelList = mOwnerList.stream() final List<String> labelList = mOwnerSet.stream()
.filter(it -> it.isOverrideable() == isOverrideable) .filter(it -> it.isOverrideable() == isOverrideable)
.map(it -> getLabel(context, it.getPackageName())) .map(it -> getLabel(context, it.getPackageName()))
.filter(label -> label != null) .filter(label -> label != null)

View File

@@ -16,6 +16,8 @@
package com.android.settings.bluetooth; package com.android.settings.bluetooth;
import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
@@ -34,8 +36,6 @@ import com.android.internal.app.AlertActivity;
import com.android.internal.app.AlertController; import com.android.internal.app.AlertController;
import com.android.settings.R; import com.android.settings.R;
import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
/** /**
* BluetoothPermissionActivity shows a dialog for accepting incoming * BluetoothPermissionActivity shows a dialog for accepting incoming
* profile connection request from untrusted devices. * profile connection request from untrusted devices.
@@ -138,7 +138,7 @@ public class BluetoothPermissionActivity extends AlertActivity implements
} }
p.mPositiveButtonText = getString(R.string.allow); p.mPositiveButtonText = getString(R.string.allow);
p.mPositiveButtonListener = this; p.mPositiveButtonListener = this;
p.mNegativeButtonText = getString(R.string.deny); p.mNegativeButtonText = getString(R.string.request_manage_bluetooth_permission_dont_allow);
p.mNegativeButtonListener = this; p.mNegativeButtonListener = this;
mOkButton = mAlert.getButton(DialogInterface.BUTTON_POSITIVE); mOkButton = mAlert.getButton(DialogInterface.BUTTON_POSITIVE);
setupAlert(); setupAlert();

View File

@@ -0,0 +1,77 @@
/*
* 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.fuelgauge;
import java.time.Duration;
/** A container class to carry battery data in a specific time slot. */
public final class BatteryDiffEntry {
private static final String TAG = "BatteryDiffEntry";
public long mForegroundUsageTimeInMs;
public long mBackgroundUsageTimeInMs;
public double mConsumePower;
// A BatteryHistEntry corresponding to this diff usage data.
public final BatteryHistEntry mBatteryHistEntry;
private double mTotalConsumePower;
private double mPercentOfTotal;
public BatteryDiffEntry(
long foregroundUsageTimeInMs,
long backgroundUsageTimeInMs,
double consumePower,
BatteryHistEntry batteryHistEntry) {
mForegroundUsageTimeInMs = foregroundUsageTimeInMs;
mBackgroundUsageTimeInMs = backgroundUsageTimeInMs;
mConsumePower = consumePower;
mBatteryHistEntry = batteryHistEntry;
}
/** Sets the total consumed power in a specific time slot. */
public void setTotalConsumePower(double totalConsumePower) {
mTotalConsumePower = totalConsumePower;
mPercentOfTotal = totalConsumePower == 0
? 0 : (mConsumePower / mTotalConsumePower) * 100.0;
}
/** Gets the percentage of total consumed power. */
public double getPercentOfTotal() {
return mPercentOfTotal;
}
/** Clones a new instance. */
public BatteryDiffEntry clone() {
return new BatteryDiffEntry(
this.mForegroundUsageTimeInMs,
this.mBackgroundUsageTimeInMs,
this.mConsumePower,
this.mBatteryHistEntry /*same instance*/);
}
@Override
public String toString() {
final StringBuilder builder = new StringBuilder()
.append("BatteryDiffEntry{")
.append("\n\tname=" + mBatteryHistEntry.mAppLabel)
.append(String.format("\n\tconsume=%.2f%% %f/%f",
mPercentOfTotal, mConsumePower, mTotalConsumePower))
.append(String.format("\n\tforeground:%d background:%d",
Duration.ofMillis(mForegroundUsageTimeInMs).getSeconds(),
Duration.ofMillis(mBackgroundUsageTimeInMs).getSeconds()))
.append(String.format("\n\tpackage:%s uid:%s",
mBatteryHistEntry.mPackageName, mBatteryHistEntry.mUid));
return builder.toString();
}
}

View File

@@ -112,6 +112,11 @@ public final class BatteryHistEntry {
return mIsValidEntry; return mIsValidEntry;
} }
/** Gets an identifier to represent this {@link BatteryHistEntry}. */
public String getKey() {
return mPackageName + "-" + mUserId;
}
@Override @Override
public String toString() { public String toString() {
final String recordAtDateTime = ConvertUtils.utcToLocalTime(mTimestamp); final String recordAtDateTime = ConvertUtils.utcToLocalTime(mTimestamp);
@@ -135,7 +140,7 @@ public final class BatteryHistEntry {
return values.getAsInteger(key); return values.getAsInteger(key);
}; };
mIsValidEntry = false; mIsValidEntry = false;
return -1; return 0;
} }
private int getInteger(Cursor cursor, String key) { private int getInteger(Cursor cursor, String key) {
@@ -144,7 +149,7 @@ public final class BatteryHistEntry {
return cursor.getInt(columnIndex); return cursor.getInt(columnIndex);
} }
mIsValidEntry = false; mIsValidEntry = false;
return -1; return 0;
} }
private long getLong(ContentValues values, String key) { private long getLong(ContentValues values, String key) {
@@ -152,7 +157,7 @@ public final class BatteryHistEntry {
return values.getAsLong(key); return values.getAsLong(key);
} }
mIsValidEntry = false; mIsValidEntry = false;
return -1L; return 0L;
} }
private long getLong(Cursor cursor, String key) { private long getLong(Cursor cursor, String key) {
@@ -161,7 +166,7 @@ public final class BatteryHistEntry {
return cursor.getLong(columnIndex); return cursor.getLong(columnIndex);
} }
mIsValidEntry = false; mIsValidEntry = false;
return -1L; return 0L;
} }
private double getDouble(ContentValues values, String key) { private double getDouble(ContentValues values, String key) {

View File

@@ -26,13 +26,22 @@ import android.util.Log;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TimeZone; import java.util.TimeZone;
/** A utility class to convert data into another types. */ /** A utility class to convert data into another types. */
public final class ConvertUtils { public final class ConvertUtils {
private static final String TAG = "ConvertUtils"; private static final String TAG = "ConvertUtils";
private static final Map<String, BatteryHistEntry> EMPTY_BATTERY_MAP = new HashMap<>();
private static final BatteryHistEntry EMPTY_BATTERY_HIST_ENTRY =
new BatteryHistEntry(new ContentValues());
/** Invalid system battery consumer drain type. */ /** Invalid system battery consumer drain type. */
public static final int INVALID_DRAIN_TYPE = -1; public static final int INVALID_DRAIN_TYPE = -1;
@@ -126,4 +135,170 @@ public final class ConvertUtils {
} }
return sSimpleDateFormat.format(new Date(timestamp)); return sSimpleDateFormat.format(new Date(timestamp));
} }
/** Gets indexed battery usage data for each corresponding time slot. */
public static Map<Integer, List<BatteryDiffEntry>> getIndexedUsageMap(
final int timeSlotSize,
final long[] batteryHistoryKeys,
final Map<Long, List<BatteryHistEntry>> batteryHistoryMap) {
final Map<Integer, List<BatteryDiffEntry>> resultMap = new HashMap<>();
// Generates a temporary map to calculate diff usage data, which converts the inputted
// List<BatteryDiffEntry> into Map<String, BatteryHistEntry> with the key comes from
// the BatteryHistEntry.getKey() method.
final Map<Long, Map<String, BatteryHistEntry>> newBatteryHistoryMap = new HashMap<>();
for (int index = 0; index < batteryHistoryKeys.length; index++) {
final Long timestamp = Long.valueOf(batteryHistoryKeys[index]);
final List<BatteryHistEntry> entries = batteryHistoryMap.get(timestamp);
if (entries == null || entries.isEmpty()) {
continue;
}
final Map<String, BatteryHistEntry> slotBatteryHistDataMap = new HashMap<>();
for (BatteryHistEntry entry : entries) {
// Excludes auto-generated fake BatteryHistEntry data,
// which is used to record battery level and status purpose only.
if (!FAKE_PACKAGE_NAME.equals(entry.mPackageName)) {
slotBatteryHistDataMap.put(entry.getKey(), entry);
}
}
newBatteryHistoryMap.put(timestamp, slotBatteryHistDataMap);
}
// Each time slot usage diff data =
// Math.abs(timestamp[i+2] data - timestamp[i+1] data) +
// Math.abs(timestamp[i+1] data - timestamp[i] data);
// since we want to aggregate every two hours data into a single time slot.
final int timestampStride = 2;
for (int index = 0; index < timeSlotSize; index++) {
final Long currentTimestamp =
Long.valueOf(batteryHistoryKeys[index * timestampStride]);
final Long nextTimestamp =
Long.valueOf(batteryHistoryKeys[index * timestampStride + 1]);
final Long nextTwoTimestamp =
Long.valueOf(batteryHistoryKeys[index * timestampStride + 2]);
// Fetches BatteryHistEntry data from corresponding time slot.
final Map<String, BatteryHistEntry> currentBatteryHistMap =
newBatteryHistoryMap.getOrDefault(currentTimestamp, EMPTY_BATTERY_MAP);
final Map<String, BatteryHistEntry> nextBatteryHistMap =
newBatteryHistoryMap.getOrDefault(nextTimestamp, EMPTY_BATTERY_MAP);
final Map<String, BatteryHistEntry> nextTwoBatteryHistMap =
newBatteryHistoryMap.getOrDefault(nextTwoTimestamp, EMPTY_BATTERY_MAP);
// Collects all keys in these three time slot records as population.
final Set<String> allBatteryHistEntryKeys = new HashSet<>();
allBatteryHistEntryKeys.addAll(currentBatteryHistMap.keySet());
allBatteryHistEntryKeys.addAll(nextBatteryHistMap.keySet());
allBatteryHistEntryKeys.addAll(nextTwoBatteryHistMap.keySet());
double totalConsumePower = 0.0;
final List<BatteryDiffEntry> batteryDiffEntryList = new ArrayList<>();
// Adds a specific time slot BatteryDiffEntry list into result map.
resultMap.put(Integer.valueOf(index), batteryDiffEntryList);
// Calculates all packages diff usage data in a specific time slot.
for (String key : allBatteryHistEntryKeys) {
final BatteryHistEntry currentEntry =
currentBatteryHistMap.getOrDefault(key, EMPTY_BATTERY_HIST_ENTRY);
final BatteryHistEntry nextEntry =
nextBatteryHistMap.getOrDefault(key, EMPTY_BATTERY_HIST_ENTRY);
final BatteryHistEntry nextTwoEntry =
nextTwoBatteryHistMap.getOrDefault(key, EMPTY_BATTERY_HIST_ENTRY);
// Cumulative values is a specific time slot for a specific app.
final long foregroundUsageTimeInMs =
getDiffValue(
currentEntry.mForegroundUsageTimeInMs,
nextEntry.mForegroundUsageTimeInMs,
nextTwoEntry.mForegroundUsageTimeInMs);
final long backgroundUsageTimeInMs =
getDiffValue(
currentEntry.mBackgroundUsageTimeInMs,
nextEntry.mBackgroundUsageTimeInMs,
nextTwoEntry.mBackgroundUsageTimeInMs);
final double consumePower =
getDiffValue(
currentEntry.mConsumePower,
nextEntry.mConsumePower,
nextTwoEntry.mConsumePower);
totalConsumePower += consumePower;
// Excludes entry since we don't have enough data to calculate.
if (foregroundUsageTimeInMs == 0
&& backgroundUsageTimeInMs == 0
&& consumePower == 0) {
continue;
}
final BatteryHistEntry selectedBatteryEntry =
selectBatteryHistEntry(currentEntry, nextEntry, nextTwoEntry);
if (selectedBatteryEntry == null) {
continue;
}
batteryDiffEntryList.add(
new BatteryDiffEntry(
foregroundUsageTimeInMs,
backgroundUsageTimeInMs,
consumePower,
selectedBatteryEntry));
}
// Sets total consume power data into all BatteryDiffEntry in the same slot.
for (BatteryDiffEntry diffEntry : batteryDiffEntryList) {
diffEntry.setTotalConsumePower(totalConsumePower);
}
}
insert24HoursData(BatteryChartView.SELECTED_INDEX_ALL, resultMap);
return resultMap;
}
private static void insert24HoursData(
final int desiredIndex,
final Map<Integer, List<BatteryDiffEntry>> indexedUsageMap) {
final Map<String, BatteryDiffEntry> resultMap = new HashMap<>();
double totalConsumePower = 0.0;
// Loops for all BatteryDiffEntry and aggregate them together.
for (List<BatteryDiffEntry> entryList : indexedUsageMap.values()) {
for (BatteryDiffEntry entry : entryList) {
final String key = entry.mBatteryHistEntry.getKey();
final BatteryDiffEntry oldBatteryDiffEntry = resultMap.get(key);
// Creates new BatteryDiffEntry if we don't have it.
if (oldBatteryDiffEntry == null) {
resultMap.put(key, entry.clone());
} else {
// Sums up some fields data into the existing one.
oldBatteryDiffEntry.mForegroundUsageTimeInMs +=
entry.mForegroundUsageTimeInMs;
oldBatteryDiffEntry.mBackgroundUsageTimeInMs +=
entry.mBackgroundUsageTimeInMs;
oldBatteryDiffEntry.mConsumePower += entry.mConsumePower;
}
totalConsumePower += entry.mConsumePower;
}
}
final List<BatteryDiffEntry> resultList = new ArrayList<>(resultMap.values());
// Sets total 24 hours consume power data into all BatteryDiffEntry.
for (BatteryDiffEntry entry : resultList) {
entry.setTotalConsumePower(totalConsumePower);
}
indexedUsageMap.put(Integer.valueOf(desiredIndex), resultList);
}
private static long getDiffValue(long v1, long v2, long v3) {
return (v2 > v1 ? v2 - v1 : 0) + (v3 > v2 ? v3 - v2 : 0);
}
private static double getDiffValue(double v1, double v2, double v3) {
return (v2 > v1 ? v2 - v1 : 0) + (v3 > v2 ? v3 - v2 : 0);
}
private static BatteryHistEntry selectBatteryHistEntry(
BatteryHistEntry entry1,
BatteryHistEntry entry2,
BatteryHistEntry entry3) {
if (entry1 != null && entry1 != EMPTY_BATTERY_HIST_ENTRY) {
return entry1;
} else if (entry2 != null && entry2 != EMPTY_BATTERY_HIST_ENTRY) {
return entry2;
} else {
return entry3 != null && entry3 != EMPTY_BATTERY_HIST_ENTRY
? entry3 : null;
}
}
} }

View File

@@ -75,11 +75,11 @@ public abstract class BatteryTip implements Comparable<BatteryTip>, Parcelable {
static final SparseIntArray TIP_ORDER; static final SparseIntArray TIP_ORDER;
static { static {
TIP_ORDER = new SparseIntArray(); TIP_ORDER = new SparseIntArray();
TIP_ORDER.append(TipType.BATTERY_DEFENDER, 0); TIP_ORDER.append(TipType.BATTERY_SAVER, 0);
TIP_ORDER.append(TipType.APP_RESTRICTION, 1); TIP_ORDER.append(TipType.LOW_BATTERY, 1);
TIP_ORDER.append(TipType.BATTERY_SAVER, 2); TIP_ORDER.append(TipType.BATTERY_DEFENDER, 2);
TIP_ORDER.append(TipType.HIGH_DEVICE_USAGE, 3); TIP_ORDER.append(TipType.APP_RESTRICTION, 3);
TIP_ORDER.append(TipType.LOW_BATTERY, 4); TIP_ORDER.append(TipType.HIGH_DEVICE_USAGE, 4);
TIP_ORDER.append(TipType.SUMMARY, 5); TIP_ORDER.append(TipType.SUMMARY, 5);
TIP_ORDER.append(TipType.SMART_BATTERY_MANAGER, 6); TIP_ORDER.append(TipType.SMART_BATTERY_MANAGER, 6);
TIP_ORDER.append(TipType.REDUCED_BATTERY, 7); TIP_ORDER.append(TipType.REDUCED_BATTERY, 7);

View File

@@ -50,6 +50,7 @@ import android.widget.Toast;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.Fragment;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
@@ -80,6 +81,7 @@ import com.android.settingslib.RestrictedLockUtilsInternal;
import com.android.settingslib.connectivity.ConnectivitySubsystemsRecoveryManager; import com.android.settingslib.connectivity.ConnectivitySubsystemsRecoveryManager;
import com.android.settingslib.search.Indexable; import com.android.settingslib.search.Indexable;
import com.android.settingslib.search.SearchIndexable; import com.android.settingslib.search.SearchIndexable;
import com.android.settingslib.utils.ThreadUtils;
import com.android.settingslib.widget.LayoutPreference; import com.android.settingslib.widget.LayoutPreference;
import com.android.settingslib.wifi.LongPressWifiEntryPreference; import com.android.settingslib.wifi.LongPressWifiEntryPreference;
import com.android.settingslib.wifi.WifiSavedConfigUtils; import com.android.settingslib.wifi.WifiSavedConfigUtils;
@@ -100,7 +102,7 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment
implements Indexable, WifiPickerTracker.WifiPickerTrackerCallback, implements Indexable, WifiPickerTracker.WifiPickerTrackerCallback,
WifiDialog2.WifiDialog2Listener, DialogInterface.OnDismissListener, WifiDialog2.WifiDialog2Listener, DialogInterface.OnDismissListener,
ConnectivitySubsystemsRecoveryManager.RecoveryStatusCallback, ConnectivitySubsystemsRecoveryManager.RecoveryStatusCallback,
AirplaneModeEnabler.OnAirplaneModeChangedListener { AirplaneModeEnabler.OnAirplaneModeChangedListener, InternetUpdater.InternetChangeListener {
public static final String ACTION_NETWORK_PROVIDER_SETTINGS = public static final String ACTION_NETWORK_PROVIDER_SETTINGS =
"android.settings.NETWORK_PROVIDER_SETTINGS"; "android.settings.NETWORK_PROVIDER_SETTINGS";
@@ -123,7 +125,10 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment
private static final String PREF_KEY_AIRPLANE_MODE_MSG = "airplane_mode_message"; private static final String PREF_KEY_AIRPLANE_MODE_MSG = "airplane_mode_message";
private static final String PREF_KEY_EMPTY_WIFI_LIST = "wifi_empty_list"; private static final String PREF_KEY_EMPTY_WIFI_LIST = "wifi_empty_list";
// TODO(b/70983952): Rename these to use WifiEntry instead of AccessPoint. // TODO(b/70983952): Rename these to use WifiEntry instead of AccessPoint.
private static final String PREF_KEY_CONNECTED_ACCESS_POINTS = "connected_access_point"; @VisibleForTesting
static final String PREF_KEY_CONNECTED_ACCESS_POINTS = "connected_access_point";
@VisibleForTesting
static final String PREF_KEY_FIRST_ACCESS_POINTS = "first_access_points";
private static final String PREF_KEY_ACCESS_POINTS = "access_points"; private static final String PREF_KEY_ACCESS_POINTS = "access_points";
private static final String PREF_KEY_CONFIGURE_WIFI_SETTINGS = "configure_wifi_settings"; private static final String PREF_KEY_CONFIGURE_WIFI_SETTINGS = "configure_wifi_settings";
private static final String PREF_KEY_SAVED_NETWORKS = "saved_networks"; private static final String PREF_KEY_SAVED_NETWORKS = "saved_networks";
@@ -192,12 +197,17 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment
@VisibleForTesting @VisibleForTesting
WifiPickerTracker mWifiPickerTracker; WifiPickerTracker mWifiPickerTracker;
private WifiPickerTrackerHelper mWifiPickerTrackerHelper; private WifiPickerTrackerHelper mWifiPickerTrackerHelper;
@VisibleForTesting
InternetUpdater mInternetUpdater;
private WifiDialog2 mDialog; private WifiDialog2 mDialog;
private View mProgressHeader; private View mProgressHeader;
private PreferenceCategory mConnectedWifiEntryPreferenceCategory; @VisibleForTesting
PreferenceCategory mConnectedWifiEntryPreferenceCategory;
@VisibleForTesting
PreferenceCategory mFirstWifiEntryPreferenceCategory;
private PreferenceCategory mWifiEntryPreferenceCategory; private PreferenceCategory mWifiEntryPreferenceCategory;
@VisibleForTesting @VisibleForTesting
AddWifiNetworkPreference mAddWifiNetworkPreference; AddWifiNetworkPreference mAddWifiNetworkPreference;
@@ -262,6 +272,7 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment
mAirplaneModeMsgPreference = findPreference(PREF_KEY_AIRPLANE_MODE_MSG); mAirplaneModeMsgPreference = findPreference(PREF_KEY_AIRPLANE_MODE_MSG);
updateAirplaneModeMsgPreference(mAirplaneModeEnabler.isAirplaneModeOn() /* visible */); updateAirplaneModeMsgPreference(mAirplaneModeEnabler.isAirplaneModeOn() /* visible */);
mConnectedWifiEntryPreferenceCategory = findPreference(PREF_KEY_CONNECTED_ACCESS_POINTS); mConnectedWifiEntryPreferenceCategory = findPreference(PREF_KEY_CONNECTED_ACCESS_POINTS);
mFirstWifiEntryPreferenceCategory = findPreference(PREF_KEY_FIRST_ACCESS_POINTS);
mWifiEntryPreferenceCategory = findPreference(PREF_KEY_ACCESS_POINTS); mWifiEntryPreferenceCategory = findPreference(PREF_KEY_ACCESS_POINTS);
mConfigureWifiSettingsPreference = findPreference(PREF_KEY_CONFIGURE_WIFI_SETTINGS); mConfigureWifiSettingsPreference = findPreference(PREF_KEY_CONFIGURE_WIFI_SETTINGS);
mSavedNetworksPreference = findPreference(PREF_KEY_SAVED_NETWORKS); mSavedNetworksPreference = findPreference(PREF_KEY_SAVED_NETWORKS);
@@ -318,6 +329,7 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment
mWifiPickerTrackerHelper = mWifiPickerTrackerHelper =
new WifiPickerTrackerHelper(getSettingsLifecycle(), getContext(), this); new WifiPickerTrackerHelper(getSettingsLifecycle(), getContext(), this);
mWifiPickerTracker = mWifiPickerTrackerHelper.getWifiPickerTracker(); mWifiPickerTracker = mWifiPickerTrackerHelper.getWifiPickerTracker();
mInternetUpdater = new InternetUpdater(getContext(), getSettingsLifecycle(), this);
final Activity activity = getActivity(); final Activity activity = getActivity();
@@ -635,6 +647,13 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment
} }
} }
@Override
public void onInternetTypeChanged(@InternetUpdater.InternetType int internetType) {
ThreadUtils.postOnMainThread(() -> {
onWifiStateChanged();
});
}
/** Called when the state of Wifi has changed. */ /** Called when the state of Wifi has changed. */
@Override @Override
public void onWifiStateChanged() { public void onWifiStateChanged() {
@@ -738,17 +757,18 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment
mWifiEntryPreferenceCategory.setVisible(true); mWifiEntryPreferenceCategory.setVisible(true);
final WifiEntry connectedEntry = mWifiPickerTracker.getConnectedWifiEntry(); final WifiEntry connectedEntry = mWifiPickerTracker.getConnectedWifiEntry();
mConnectedWifiEntryPreferenceCategory.setVisible(connectedEntry != null); PreferenceCategory connectedWifiPreferenceCategory = getConnectedWifiPreferenceCategory();
connectedWifiPreferenceCategory.setVisible(connectedEntry != null);
if (connectedEntry != null) { if (connectedEntry != null) {
final LongPressWifiEntryPreference connectedPref = final LongPressWifiEntryPreference connectedPref =
mConnectedWifiEntryPreferenceCategory.findPreference(connectedEntry.getKey()); connectedWifiPreferenceCategory.findPreference(connectedEntry.getKey());
if (connectedPref == null || connectedPref.getWifiEntry() != connectedEntry) { if (connectedPref == null || connectedPref.getWifiEntry() != connectedEntry) {
mConnectedWifiEntryPreferenceCategory.removeAll(); connectedWifiPreferenceCategory.removeAll();
final ConnectedWifiEntryPreference pref = final ConnectedWifiEntryPreference pref =
new ConnectedWifiEntryPreference(getPrefContext(), connectedEntry, this); createConnectedWifiEntryPreference(connectedEntry);
pref.setKey(connectedEntry.getKey()); pref.setKey(connectedEntry.getKey());
pref.refresh(); pref.refresh();
mConnectedWifiEntryPreferenceCategory.addPreference(pref); connectedWifiPreferenceCategory.addPreference(pref);
pref.setOnPreferenceClickListener(preference -> { pref.setOnPreferenceClickListener(preference -> {
if (connectedEntry.canSignIn()) { if (connectedEntry.canSignIn()) {
connectedEntry.signIn(null /* callback */); connectedEntry.signIn(null /* callback */);
@@ -763,11 +783,11 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment
if (mClickedConnect) { if (mClickedConnect) {
mClickedConnect = false; mClickedConnect = false;
scrollToPreference(mConnectedWifiEntryPreferenceCategory); scrollToPreference(connectedWifiPreferenceCategory);
} }
} }
} else { } else {
mConnectedWifiEntryPreferenceCategory.removeAll(); connectedWifiPreferenceCategory.removeAll();
} }
int index = 0; int index = 0;
@@ -821,6 +841,27 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment
setAdditionalSettingsSummaries(); setAdditionalSettingsSummaries();
} }
@VisibleForTesting
PreferenceCategory getConnectedWifiPreferenceCategory() {
if (mInternetUpdater.getInternetType() == InternetUpdater.INTERNET_WIFI) {
mFirstWifiEntryPreferenceCategory.setVisible(false);
mFirstWifiEntryPreferenceCategory.removeAll();
return mConnectedWifiEntryPreferenceCategory;
}
mConnectedWifiEntryPreferenceCategory.setVisible(false);
mConnectedWifiEntryPreferenceCategory.removeAll();
return mFirstWifiEntryPreferenceCategory;
}
@VisibleForTesting
ConnectedWifiEntryPreference createConnectedWifiEntryPreference(WifiEntry wifiEntry) {
if (mInternetUpdater.getInternetType() == InternetUpdater.INTERNET_WIFI) {
return new ConnectedWifiEntryPreference(getPrefContext(), wifiEntry, this);
}
return new FirstWifiEntryPreference(getPrefContext(), wifiEntry, this);
}
private void launchNetworkDetailsFragment(LongPressWifiEntryPreference pref) { private void launchNetworkDetailsFragment(LongPressWifiEntryPreference pref) {
final WifiEntry wifiEntry = pref.getWifiEntry(); final WifiEntry wifiEntry = pref.getWifiEntry();
final Context context = getContext(); final Context context = getContext();
@@ -1217,4 +1258,22 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment
public void onAirplaneModeChanged(boolean isAirplaneModeOn) { public void onAirplaneModeChanged(boolean isAirplaneModeOn) {
updateAirplaneModeMsgPreference(isAirplaneModeOn /* visible */); updateAirplaneModeMsgPreference(isAirplaneModeOn /* visible */);
} }
/**
* A Wi-Fi preference for the connected Wi-Fi network without internet access.
*
* Override the icon color attribute by {@link ConnectedWifiEntryPreference#getIconColorAttr()}
* and show the icon color to android.R.attr.colorControlNormal for the preference.
*/
public class FirstWifiEntryPreference extends ConnectedWifiEntryPreference {
public FirstWifiEntryPreference(Context context, WifiEntry wifiEntry,
Fragment fragment) {
super(context, wifiEntry, fragment);
}
@Override
protected int getIconColorAttr() {
return android.R.attr.colorControlNormal;
}
}
} }

View File

@@ -153,7 +153,7 @@ class ConfigDialog extends AlertDialog implements TextWatcher,
mL2tpSecret.setTextAppearance(android.R.style.TextAppearance_DeviceDefault_Medium); mL2tpSecret.setTextAppearance(android.R.style.TextAppearance_DeviceDefault_Medium);
mIpsecIdentifier.setText(mProfile.ipsecIdentifier); mIpsecIdentifier.setText(mProfile.ipsecIdentifier);
mIpsecSecret.setText(mProfile.ipsecSecret); mIpsecSecret.setText(mProfile.ipsecSecret);
AndroidKeystoreAliasLoader androidKeystoreAliasLoader = final AndroidKeystoreAliasLoader androidKeystoreAliasLoader =
new AndroidKeystoreAliasLoader(null); new AndroidKeystoreAliasLoader(null);
loadCertificates(mIpsecUserCert, androidKeystoreAliasLoader.getKeyCertAliases(), 0, loadCertificates(mIpsecUserCert, androidKeystoreAliasLoader.getKeyCertAliases(), 0,
mProfile.ipsecUserCert); mProfile.ipsecUserCert);

View File

@@ -0,0 +1,52 @@
/*
* 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.fuelgauge;
import static com.google.common.truth.Truth.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class)
public final class BatteryDiffEntryTest {
@Test
public void testSetTotalConsumePower_returnExpectedResult() {
final BatteryDiffEntry entry =
new BatteryDiffEntry(
/*foregroundUsageTimeInMs=*/ 10001L,
/*backgroundUsageTimeInMs=*/ 20002L,
/*consumePower=*/ 22.0,
/*batteryHistEntry=*/ null);
entry.setTotalConsumePower(100.0);
assertThat(entry.getPercentOfTotal()).isEqualTo(22.0);
}
@Test
public void testSetTotalConsumePower_setZeroValue_returnsZeroValue() {
final BatteryDiffEntry entry =
new BatteryDiffEntry(
/*foregroundUsageTimeInMs=*/ 10001L,
/*backgroundUsageTimeInMs=*/ 20002L,
/*consumePower=*/ 22.0,
/*batteryHistEntry=*/ null);
entry.setTotalConsumePower(0);
assertThat(entry.getPercentOfTotal()).isEqualTo(0);
}
}

View File

@@ -161,5 +161,7 @@ public final class BatteryHistEntryTest {
.isEqualTo(BatteryManager.BATTERY_STATUS_FULL); .isEqualTo(BatteryManager.BATTERY_STATUS_FULL);
assertThat(entry.mBatteryHealth) assertThat(entry.mBatteryHealth)
.isEqualTo(BatteryManager.BATTERY_HEALTH_COLD); .isEqualTo(BatteryManager.BATTERY_HEALTH_COLD);
assertThat(entry.getKey())
.isEqualTo("com.google.android.settings.battery-" + entry.mUserId);
} }
} }

View File

@@ -37,6 +37,11 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TimeZone; import java.util.TimeZone;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
@@ -165,4 +170,84 @@ public final class ConvertUtilsTest {
assertThat(ConvertUtils.getConsumerType(mockBatteryConsumer)) assertThat(ConvertUtils.getConsumerType(mockBatteryConsumer))
.isEqualTo(ConvertUtils.CONSUMER_TYPE_UNKNOWN); .isEqualTo(ConvertUtils.CONSUMER_TYPE_UNKNOWN);
} }
@Test
public void testGetIndexedUsageMap_returnsExpectedResult() {
// Creates the fake testing data.
final int timeSlotSize = 2;
final long[] batteryHistoryKeys = new long[] {101L, 102L, 103L, 104L, 105L};
final Map<Long, List<BatteryHistEntry>> batteryHistoryMap = new HashMap<>();
batteryHistoryMap.put(
Long.valueOf(batteryHistoryKeys[0]),
Arrays.asList(
createBatteryHistEntry(
"package1", "label1", 5.0, 1L, 10L, 20L)));
batteryHistoryMap.put(
Long.valueOf(batteryHistoryKeys[1]), new ArrayList<BatteryHistEntry>());
batteryHistoryMap.put(
Long.valueOf(batteryHistoryKeys[2]),
Arrays.asList(
createBatteryHistEntry(
"package2", "label2", 10.0, 2L, 15L, 25L)));
batteryHistoryMap.put(
Long.valueOf(batteryHistoryKeys[3]),
Arrays.asList(
createBatteryHistEntry(
"package2", "label2", 15.0, 2L, 25L, 35L),
createBatteryHistEntry(
"package3", "label3", 5.0, 2L, 5L, 5L)));
batteryHistoryMap.put(
Long.valueOf(batteryHistoryKeys[4]),
Arrays.asList(
createBatteryHistEntry(
"package2", "label2", 30.0, 2L, 30L, 40L),
createBatteryHistEntry(
"package2", "label2", 75.0, 3L, 40L, 50L),
createBatteryHistEntry(
"package3", "label3", 5.0, 2L, 5L, 5L)));
final Map<Integer, List<BatteryDiffEntry>> resultMap =
ConvertUtils.getIndexedUsageMap(
timeSlotSize, batteryHistoryKeys, batteryHistoryMap);
assertThat(resultMap).hasSize(3);
// Verifies the first timestamp result.
List<BatteryDiffEntry> entryList = resultMap.get(Integer.valueOf(0));
assertThat(entryList).hasSize(1);
assertBatteryDiffEntry(entryList.get(0), 100, 15L, 25L);
// Verifies the second timestamp result.
entryList = resultMap.get(Integer.valueOf(1));
assertThat(entryList).hasSize(3);
assertBatteryDiffEntry(entryList.get(0), 5, 5L, 5L);
assertBatteryDiffEntry(entryList.get(1), 75, 40L, 50L);
assertBatteryDiffEntry(entryList.get(2), 20, 15L, 15L);
// Verifies the last 24 hours aggregate result.
entryList = resultMap.get(Integer.valueOf(-1));
assertThat(entryList).hasSize(3);
assertBatteryDiffEntry(entryList.get(0), 4, 5L, 5L);
assertBatteryDiffEntry(entryList.get(1), 68, 40L, 50L);
assertBatteryDiffEntry(entryList.get(2), 27, 30L, 40L);
}
private static BatteryHistEntry createBatteryHistEntry(
String packageName, String appLabel, double consumePower,
long userId, long foregroundUsageTimeInMs, long backgroundUsageTimeInMs) {
// Only insert required fields.
final ContentValues values = new ContentValues();
values.put("packageName", packageName);
values.put("appLabel", appLabel);
values.put("userId", userId);
values.put("consumePower", consumePower);
values.put("foregroundUsageTimeInMs", foregroundUsageTimeInMs);
values.put("backgroundUsageTimeInMs", backgroundUsageTimeInMs);
return new BatteryHistEntry(values);
}
private static void assertBatteryDiffEntry(
BatteryDiffEntry entry, int percentOfTotal,
long foregroundUsageTimeInMs, long backgroundUsageTimeInMs) {
assertThat((int) entry.getPercentOfTotal()).isEqualTo(percentOfTotal);
assertThat(entry.mForegroundUsageTimeInMs).isEqualTo(foregroundUsageTimeInMs);
assertThat(entry.mBackgroundUsageTimeInMs).isEqualTo(backgroundUsageTimeInMs);
}
} }

View File

@@ -50,10 +50,10 @@ import java.util.List;
public class BatteryTipLoaderTest { public class BatteryTipLoaderTest {
private static final int[] TIP_ORDER = { private static final int[] TIP_ORDER = {
BatteryTip.TipType.BATTERY_DEFENDER,
BatteryTip.TipType.BATTERY_SAVER, BatteryTip.TipType.BATTERY_SAVER,
BatteryTip.TipType.HIGH_DEVICE_USAGE,
BatteryTip.TipType.LOW_BATTERY, BatteryTip.TipType.LOW_BATTERY,
BatteryTip.TipType.BATTERY_DEFENDER,
BatteryTip.TipType.HIGH_DEVICE_USAGE,
BatteryTip.TipType.SMART_BATTERY_MANAGER}; BatteryTip.TipType.SMART_BATTERY_MANAGER};
@Mock(answer = Answers.RETURNS_DEEP_STUBS) @Mock(answer = Answers.RETURNS_DEEP_STUBS)
private BatteryUsageStats mBatteryUsageStats; private BatteryUsageStats mBatteryUsageStats;

View File

@@ -51,6 +51,7 @@ import android.view.View;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
@@ -61,6 +62,7 @@ import com.android.settings.datausage.DataUsagePreference;
import com.android.settings.testutils.shadow.ShadowDataUsageUtils; import com.android.settings.testutils.shadow.ShadowDataUsageUtils;
import com.android.settings.testutils.shadow.ShadowFragment; import com.android.settings.testutils.shadow.ShadowFragment;
import com.android.settings.wifi.AddWifiNetworkPreference; import com.android.settings.wifi.AddWifiNetworkPreference;
import com.android.settings.wifi.ConnectedWifiEntryPreference;
import com.android.settings.wifi.WifiConfigController2; import com.android.settings.wifi.WifiConfigController2;
import com.android.settings.wifi.WifiDialog2; import com.android.settings.wifi.WifiDialog2;
import com.android.settingslib.connectivity.ConnectivitySubsystemsRecoveryManager; import com.android.settingslib.connectivity.ConnectivitySubsystemsRecoveryManager;
@@ -109,6 +111,12 @@ public class NetworkProviderSettingsTest {
private LayoutPreference mResetInternetPreference; private LayoutPreference mResetInternetPreference;
@Mock @Mock
private MenuItem mMenuItem; private MenuItem mMenuItem;
@Mock
InternetUpdater mInternetUpdater;
@Mock
PreferenceCategory mConnectedWifiEntryPreferenceCategory;
@Mock
PreferenceCategory mFirstWifiEntryPreferenceCategory;
@Before @Before
public void setUp() { public void setUp() {
@@ -132,6 +140,15 @@ public class NetworkProviderSettingsTest {
mNetworkProviderSettings.mResetInternetPreference = mResetInternetPreference; mNetworkProviderSettings.mResetInternetPreference = mResetInternetPreference;
mNetworkProviderSettings.mAirplaneModeMsgPreference = mAirplaneModeMsgPreference; mNetworkProviderSettings.mAirplaneModeMsgPreference = mAirplaneModeMsgPreference;
mNetworkProviderSettings.mAirplaneModeEnabler = mAirplaneModeEnabler; mNetworkProviderSettings.mAirplaneModeEnabler = mAirplaneModeEnabler;
mNetworkProviderSettings.mInternetUpdater = mInternetUpdater;
doReturn(NetworkProviderSettings.PREF_KEY_CONNECTED_ACCESS_POINTS)
.when(mConnectedWifiEntryPreferenceCategory).getKey();
mNetworkProviderSettings.mConnectedWifiEntryPreferenceCategory =
mConnectedWifiEntryPreferenceCategory;
doReturn(NetworkProviderSettings.PREF_KEY_FIRST_ACCESS_POINTS)
.when(mFirstWifiEntryPreferenceCategory).getKey();
mNetworkProviderSettings.mFirstWifiEntryPreferenceCategory =
mFirstWifiEntryPreferenceCategory;
FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SETTINGS_PROVIDER_MODEL, false); FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SETTINGS_PROVIDER_MODEL, false);
} }
@@ -452,11 +469,48 @@ public class NetworkProviderSettingsTest {
verify(mAirplaneModeMsgPreference).setVisible(true); verify(mAirplaneModeMsgPreference).setVisible(true);
} }
@Test @Test
public void onAirplaneModeChanged_apmIsOff_hideApmMsg() { public void onAirplaneModeChanged_apmIsOff_hideApmMsg() {
mNetworkProviderSettings.onAirplaneModeChanged(false); mNetworkProviderSettings.onAirplaneModeChanged(false);
verify(mAirplaneModeMsgPreference).setVisible(false); verify(mAirplaneModeMsgPreference).setVisible(false);
} }
@Test
public void getConnectedWifiPreferenceCategory_internetWiFi_getConnectedAccessPoints() {
doReturn(InternetUpdater.INTERNET_WIFI).when(mInternetUpdater).getInternetType();
final PreferenceCategory pc = mNetworkProviderSettings.getConnectedWifiPreferenceCategory();
assertThat(pc.getKey()).isEqualTo(NetworkProviderSettings.PREF_KEY_CONNECTED_ACCESS_POINTS);
}
@Test
public void getConnectedWifiPreferenceCategory_internetCellular_getFirstAccessPoints() {
doReturn(InternetUpdater.INTERNET_CELLULAR).when(mInternetUpdater).getInternetType();
final PreferenceCategory pc = mNetworkProviderSettings.getConnectedWifiPreferenceCategory();
assertThat(pc.getKey()).isEqualTo(NetworkProviderSettings.PREF_KEY_FIRST_ACCESS_POINTS);
}
@Test
public void createConnectedWifiEntryPreference_internetWiFi_createConnectedPreference() {
final WifiEntry wifiEntry = mock(WifiEntry.class);
doReturn(InternetUpdater.INTERNET_WIFI).when(mInternetUpdater).getInternetType();
final Preference p = mNetworkProviderSettings.createConnectedWifiEntryPreference(wifiEntry);
assertThat(p instanceof ConnectedWifiEntryPreference).isTrue();
}
@Test
public void createConnectedWifiEntryPreference_internetCellular_createFirstWifiPreference() {
final WifiEntry wifiEntry = mock(WifiEntry.class);
doReturn(InternetUpdater.INTERNET_CELLULAR).when(mInternetUpdater).getInternetType();
final Preference p = mNetworkProviderSettings.createConnectedWifiEntryPreference(wifiEntry);
assertThat(p instanceof NetworkProviderSettings.FirstWifiEntryPreference).isTrue();
}
} }