Snap for 10600946 from 270b7ef18d to udc-qpr1-release
Change-Id: I57261d59217c9d7e9e222d910e99d6f5b255f380
This commit is contained in:
22
res/drawable/battery_tips_all_rounded_bg.xml
Normal file
22
res/drawable/battery_tips_all_rounded_bg.xml
Normal file
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2023 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.
|
||||
-->
|
||||
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="@color/settingslib_dialog_background" />
|
||||
<corners android:radius="@dimen/battery_tips_card_corner_radius_normal" />
|
||||
</shape>
|
||||
27
res/drawable/battery_tips_half_rounded_bottom_bg.xml
Normal file
27
res/drawable/battery_tips_half_rounded_bottom_bg.xml
Normal file
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2023 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.
|
||||
-->
|
||||
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="@color/settingslib_dialog_background"/>
|
||||
<corners
|
||||
android:topLeftRadius="@dimen/battery_tips_card_corner_radius_small"
|
||||
android:topRightRadius="@dimen/battery_tips_card_corner_radius_small"
|
||||
android:bottomLeftRadius="@dimen/battery_tips_card_corner_radius_normal"
|
||||
android:bottomRightRadius="@dimen/battery_tips_card_corner_radius_normal"
|
||||
/>
|
||||
</shape>
|
||||
27
res/drawable/battery_tips_half_rounded_top_bg.xml
Normal file
27
res/drawable/battery_tips_half_rounded_top_bg.xml
Normal file
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2023 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.
|
||||
-->
|
||||
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="@color/settingslib_dialog_background"/>
|
||||
<corners
|
||||
android:topLeftRadius="@dimen/battery_tips_card_corner_radius_normal"
|
||||
android:topRightRadius="@dimen/battery_tips_card_corner_radius_normal"
|
||||
android:bottomLeftRadius="@dimen/battery_tips_card_corner_radius_small"
|
||||
android:bottomRightRadius="@dimen/battery_tips_card_corner_radius_small"
|
||||
/>
|
||||
</shape>
|
||||
25
res/drawable/ic_battery_charger.xml
Normal file
25
res/drawable/ic_battery_charger.xml
Normal file
@@ -0,0 +1,25 @@
|
||||
<!--
|
||||
Copyright (C) 2023 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="48dp"
|
||||
android:height="48dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="?android:attr/colorAccent"
|
||||
android:pathData="M442,780L518,780L518,698L660,542L660,351Q660,351 660,351Q660,351 660,351L300,351Q300,351 300,351Q300,351 300,351L300,542L442,697.7L442,780ZM382,840L382,722L240,566L240,351Q240,326.25 257.63,308.63Q275.25,291 300,291L372,291L342,321L342,120L402,120L402,291L558,291L558,120L618,120L618,321L588,291L660,291Q684.75,291 702.38,308.63Q720,326.25 720,351L720,566L578,722L578,840L382,840ZM480,565L480,565L480,565L480,565Q480,565 480,565Q480,565 480,565L480,565Q480,565 480,565Q480,565 480,565L480,565L480,565L480,565L480,565Z"/>
|
||||
</vector>
|
||||
|
||||
25
res/drawable/ic_battery_tips_close.xml
Normal file
25
res/drawable/ic_battery_tips_close.xml
Normal file
@@ -0,0 +1,25 @@
|
||||
<!--
|
||||
Copyright (C) 2023 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">
|
||||
<path
|
||||
android:fillColor="?android:attr/textColorSecondary"
|
||||
android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12 19,6.41z"/>
|
||||
</vector>
|
||||
32
res/drawable/ic_battery_tips_close_icon.xml
Normal file
32
res/drawable/ic_battery_tips_close_icon.xml
Normal file
@@ -0,0 +1,32 @@
|
||||
<!--
|
||||
Copyright (C) 2023 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.
|
||||
-->
|
||||
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp">
|
||||
<item>
|
||||
<shape android:shape="oval">
|
||||
<size
|
||||
android:width="24dp"
|
||||
android:height="24dp" />
|
||||
<solid android:color="?android:attr/colorBackground" />
|
||||
</shape>
|
||||
</item>
|
||||
<item android:drawable="@drawable/ic_battery_tips_close"
|
||||
android:gravity="center"
|
||||
android:width="16dp"
|
||||
android:height="16dp"/>
|
||||
</layer-list>
|
||||
25
res/drawable/ic_battery_tips_lightbulb.xml
Normal file
25
res/drawable/ic_battery_tips_lightbulb.xml
Normal file
@@ -0,0 +1,25 @@
|
||||
<!--
|
||||
Copyright (C) 2023 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="32dp"
|
||||
android:height="32dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="?android:attr/colorAccent"
|
||||
android:pathData="M7,20h4c0,1.1 -0.9,2 -2,2S7,21.1 7,20zM5,19h8v-2H5V19zM16.5,9.5c0,3.82 -2.66,5.86 -3.77,6.5H5.27C4.16,15.36 1.5,13.32 1.5,9.5C1.5,5.36 4.86,2 9,2S16.5,5.36 16.5,9.5zM14.5,9.5C14.5,6.47 12.03,4 9,4S3.5,6.47 3.5,9.5c0,2.47 1.49,3.89 2.35,4.5h6.3C13.01,13.39 14.5,11.97 14.5,9.5zM21.37,7.37L20,8l1.37,0.63L22,10l0.63,-1.37L24,8l-1.37,-0.63L22,6L21.37,7.37zM19,6l0.94,-2.06L22,3l-2.06,-0.94L19,0l-0.94,2.06L16,3l2.06,0.94L19,6z"/>
|
||||
</vector>
|
||||
25
res/drawable/ic_battery_tips_thumb_down.xml
Normal file
25
res/drawable/ic_battery_tips_thumb_down.xml
Normal file
@@ -0,0 +1,25 @@
|
||||
<!--
|
||||
Copyright (C) 2023 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="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="?android:attr/colorAccent"
|
||||
android:pathData="M242,120L686,120L686,632L408,920L369,889Q363,884 360,875Q357,866 357,853L357,843L402,632L103,632Q79,632 61,614Q43,596 43,572L43,490.16Q43,483 41.5,475.5Q40,468 43,461L169,171Q177.88,149.75 198.6,134.88Q219.31,120 242,120ZM626,180L229,180Q229,180 229,180Q229,180 229,180L103,479L103,572Q103,572 103,572Q103,572 103,572L476,572L423,821L626,607L626,180ZM626,607L626,607L626,572L626,572Q626,572 626,572Q626,572 626,572L626,479L626,180Q626,180 626,180Q626,180 626,180L626,180L626,607ZM686,632L686,572L819,572L819,180L686,180L686,120L879,120L879,632L686,632Z" />
|
||||
</vector>
|
||||
25
res/drawable/ic_battery_tips_thumb_up.xml
Normal file
25
res/drawable/ic_battery_tips_thumb_up.xml
Normal file
@@ -0,0 +1,25 @@
|
||||
<!--
|
||||
Copyright (C) 2023 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="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="?android:attr/colorAccent"
|
||||
android:pathData="M716,840L272,840L272,328L550,40L589,71Q595,76 598,85Q601,94 601,107L601,117L556,328L855,328Q879,328 897,346Q915,364 915,388L915,469.84Q915,477 916.5,484.5Q918,492 915,499L789,789Q780.12,810.25 759.41,825.13Q738.69,840 716,840ZM332,780L729,780Q729,780 729,780Q729,780 729,780L855,481L855,388Q855,388 855,388Q855,388 855,388L482,388L535,139L332,353L332,780ZM332,353L332,353L332,388L332,388Q332,388 332,388Q332,388 332,388L332,481L332,780Q332,780 332,780Q332,780 332,780L332,780L332,353ZM272,328L272,388L139,388L139,780L272,780L272,840L79,840L79,328L272,328Z" />
|
||||
</vector>
|
||||
125
res/layout/battery_tips_card.xml
Normal file
125
res/layout/battery_tips_card.xml
Normal file
@@ -0,0 +1,125 @@
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/battery_tips_card"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/tips_card"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/battery_tips_all_rounded_bg"
|
||||
android:orientation="vertical"
|
||||
android:padding="24dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical|start"
|
||||
android:src="@drawable/ic_battery_tips_lightbulb" />
|
||||
|
||||
<Space
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/dismiss_button"
|
||||
style="@style/Banner.Dismiss.SettingsLib"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical|end"
|
||||
android:layout_marginEnd="0dp"
|
||||
android:src="@drawable/ic_battery_tips_close_icon" />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:maxLines="2"
|
||||
android:textAlignment="viewStart"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:textColor="?android:attr/textColorPrimary" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/summary"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:gravity="start"
|
||||
android:maxLines="10"
|
||||
android:textAlignment="viewStart"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:textColor="?android:attr/textColorSecondary" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/action_button"
|
||||
style="@style/Widget.Material3.Button.OutlinedButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end"
|
||||
android:layout_marginTop="8dp"
|
||||
android:text="@string/battery_tips_card_action_button"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textStyle="bold"
|
||||
app:strokeColor="?android:attr/colorAccent"
|
||||
app:strokeWidth="1dp" />
|
||||
</LinearLayout>
|
||||
|
||||
<Space
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="1dp"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/feedback_card"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/battery_tips_half_rounded_bottom_bg"
|
||||
android:gravity="center_vertical|start"
|
||||
android:orientation="horizontal"
|
||||
android:paddingHorizontal="24dp"
|
||||
android:paddingVertical="16dp"
|
||||
android:visibility="gone">
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="0dp"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/battery_tips_card_feedback_info"
|
||||
android:textAlignment="viewStart"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textStyle="bold"/>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/thumb_up"
|
||||
style="@style/Banner.Dismiss.SettingsLib"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical|end"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:src="@drawable/ic_battery_tips_thumb_up" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/thumb_down"
|
||||
style="@style/Banner.Dismiss.SettingsLib"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical|end"
|
||||
android:src="@drawable/ic_battery_tips_thumb_down" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
@@ -373,6 +373,10 @@
|
||||
<dimen name="chartview_trapezoid_margin_start">1dp</dimen>
|
||||
<dimen name="chartview_trapezoid_margin_bottom">2dp</dimen>
|
||||
|
||||
<!-- Battery tips card view component -->
|
||||
<dimen name="battery_tips_card_corner_radius_small">4dp</dimen>
|
||||
<dimen name="battery_tips_card_corner_radius_normal">24dp</dimen>
|
||||
|
||||
<!-- Dimensions for Dream settings cards -->
|
||||
<dimen name="dream_item_min_column_width">174dp</dimen>
|
||||
<dimen name="dream_item_corner_radius">28dp</dimen>
|
||||
|
||||
@@ -9650,6 +9650,24 @@
|
||||
<!-- Preference summary for battery usage list page[CHAR_LIMIT=50]-->
|
||||
<string name="app_battery_usage_summary">Set battery usage for apps</string>
|
||||
|
||||
<!-- Label of action button in battery tips card [CHAR LIMIT=NONE] -->
|
||||
<string name="battery_tips_card_action_button" translatable="false">Optimize</string>
|
||||
|
||||
<!-- Feedback card message in battery tips card [CHAR LIMIT=NONE] -->
|
||||
<string name="battery_tips_card_feedback_info" translatable="false">Is this message helpful?</string>
|
||||
|
||||
<!-- Title of battery tips: adaptive brightness [CHAR LIMIT=NONE] -->
|
||||
<string name="battery_tips_adaptive_brightness_title" translatable="false">Turn on adaptive brightness to extend battery life</string>
|
||||
|
||||
<!-- Summary of battery tips: adaptive brightness [CHAR LIMIT=NONE] -->
|
||||
<string name="battery_tips_adaptive_brightness_summary" translatable="false">It will help reduce your daily battery drain by 10%</string>
|
||||
|
||||
<!-- Title of battery tips: reduce screen timeout [CHAR LIMIT=NONE] -->
|
||||
<string name="battery_tips_screen_timeout_title" translatable="false">Reduce screen timeout to extend battery life</string>
|
||||
|
||||
<!-- Summary of battery tips: reduce screen timeout [CHAR LIMIT=NONE] -->
|
||||
<string name="battery_tips_screen_timeout_summary" translatable="false">It will help reduce your daily battery drain by 10%</string>
|
||||
|
||||
<!-- Filter title for battery unrestricted[CHAR_LIMIT=50]-->
|
||||
<string name="filter_battery_unrestricted_title">Unrestricted</string>
|
||||
|
||||
|
||||
@@ -21,6 +21,18 @@
|
||||
android:title="@string/advanced_battery_title"
|
||||
settings:keywords="@string/keywords_battery_usage">
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="battery_tips_category"
|
||||
settings:controller=
|
||||
"com.android.settings.fuelgauge.batteryusage.BatteryTipsController"
|
||||
settings:isPreferenceVisible="false">
|
||||
|
||||
<com.android.settings.fuelgauge.batteryusage.BatteryTipsCardPreference
|
||||
android:key="battery_tips_card"
|
||||
settings:isPreferenceVisible="false" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<com.android.settings.fuelgauge.batteryusage.BatteryHistoryPreference
|
||||
android:key="battery_chart"
|
||||
settings:controller=
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
package com.android.settings.fuelgauge;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.provider.Settings;
|
||||
@@ -25,8 +25,6 @@ import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.fuelgauge.BatteryOptimizeHistoricalLogEntry;
|
||||
import com.android.settings.fuelgauge.batterysaver.BatterySaverScheduleRadioButtonsController;
|
||||
import com.android.settingslib.fuelgauge.BatterySaverUtils;
|
||||
|
||||
@@ -41,6 +39,7 @@ public final class BatterySettingsMigrateChecker extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Log.d(TAG, "onReceive: " + intent + " owner: " + BatteryBackupHelper.isOwner());
|
||||
if (intent != null
|
||||
&& Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())
|
||||
&& BatteryBackupHelper.isOwner()) {
|
||||
|
||||
@@ -37,6 +37,16 @@ public interface PowerUsageFeatureProvider {
|
||||
*/
|
||||
boolean isBatteryUsageEnabled();
|
||||
|
||||
/**
|
||||
* Check whether the battery tips card is enabled in the battery usage page
|
||||
*/
|
||||
boolean isBatteryTipsEnabled();
|
||||
|
||||
/**
|
||||
* Check whether the feedback card is enabled in the battery tips card
|
||||
*/
|
||||
boolean isBatteryTipsFeedbackEnabled();
|
||||
|
||||
/**
|
||||
* Returns a threshold (in milliseconds) for the minimal screen on time in battery usage list
|
||||
*/
|
||||
|
||||
@@ -75,6 +75,16 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBatteryTipsEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBatteryTipsFeedbackEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBatteryUsageListScreenOnTimeThresholdInMs() {
|
||||
return 0;
|
||||
|
||||
@@ -52,7 +52,7 @@ public final class IncompatibleChargerTip extends BatteryTip {
|
||||
|
||||
@Override
|
||||
public int getIconId() {
|
||||
return R.drawable.ic_battery_alert_theme;
|
||||
return R.drawable.ic_battery_charger;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -98,6 +98,20 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
|
||||
void onScreenOnTimeUpdated(Long screenOnTime, String slotTimestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* A callback listener for the battery tips card is updated.
|
||||
* This happens when battery tips card is ready.
|
||||
*/
|
||||
public interface OnBatteryTipsUpdatedListener {
|
||||
/**
|
||||
* The callback function for the battery tips card is updated.
|
||||
* @param title the title of the battery tip card
|
||||
* @param summary the summary of the battery tip card
|
||||
*/
|
||||
void onBatteryTipsUpdated(String title, String summary);
|
||||
}
|
||||
|
||||
|
||||
@VisibleForTesting
|
||||
Context mPrefContext;
|
||||
@VisibleForTesting
|
||||
@@ -119,6 +133,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
|
||||
private List<BatteryChartViewModel> mHourlyViewModels;
|
||||
private OnBatteryUsageUpdatedListener mOnBatteryUsageUpdatedListener;
|
||||
private OnScreenOnTimeUpdatedListener mOnScreenOnTimeUpdatedListener;
|
||||
private OnBatteryTipsUpdatedListener mOnBatteryTipsUpdatedListener;
|
||||
|
||||
private final SettingsActivity mActivity;
|
||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
@@ -209,6 +224,10 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
|
||||
mOnScreenOnTimeUpdatedListener = listener;
|
||||
}
|
||||
|
||||
void setOnBatteryTipsUpdatedListener(OnBatteryTipsUpdatedListener listener) {
|
||||
mOnBatteryTipsUpdatedListener = listener;
|
||||
}
|
||||
|
||||
void setBatteryHistoryMap(
|
||||
final Map<Long, Map<String, BatteryHistEntry>> batteryHistoryMap) {
|
||||
Log.d(TAG, "setBatteryHistoryMap() " + (batteryHistoryMap == null ? "null"
|
||||
@@ -344,6 +363,10 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
|
||||
}
|
||||
mOnBatteryUsageUpdatedListener.onBatteryUsageUpdated(
|
||||
slotUsageData, getSlotInformation(), isBatteryUsageMapNullOrEmpty());
|
||||
|
||||
if (mOnBatteryTipsUpdatedListener != null) {
|
||||
mOnBatteryTipsUpdatedListener.onBatteryTipsUpdated(null, null);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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.batteryusage;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
import com.google.android.material.button.MaterialButton;
|
||||
|
||||
/**
|
||||
* A preference for displaying the battery tips card view.
|
||||
*/
|
||||
public class BatteryTipsCardPreference extends Preference implements View.OnClickListener {
|
||||
|
||||
private static final String TAG = "BatteryTipsCardPreference";
|
||||
|
||||
private final PowerUsageFeatureProvider mPowerUsageFeatureProvider;
|
||||
|
||||
private MaterialButton mActionButton;
|
||||
private ImageButton mDismissButton;
|
||||
private ImageButton mThumbUpButton;
|
||||
private ImageButton mThumbDownButton;
|
||||
private CharSequence mTitle;
|
||||
private CharSequence mSummary;
|
||||
|
||||
public BatteryTipsCardPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setLayoutResource(R.layout.battery_tips_card);
|
||||
setSelectable(false);
|
||||
mPowerUsageFeatureProvider = FeatureFactory.getFactory(context)
|
||||
.getPowerUsageFeatureProvider(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitle(CharSequence title) {
|
||||
mTitle = title;
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSummary(CharSequence summary) {
|
||||
mSummary = summary;
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
// TODO: replace with the settings anomaly obtained from detectSettingsAnomaly();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder view) {
|
||||
super.onBindViewHolder(view);
|
||||
|
||||
((TextView) view.findViewById(R.id.title)).setText(mTitle);
|
||||
((TextView) view.findViewById(R.id.summary)).setText(mSummary);
|
||||
|
||||
mActionButton = (MaterialButton) view.findViewById(R.id.action_button);
|
||||
mActionButton.setOnClickListener(this);
|
||||
mDismissButton = (ImageButton) view.findViewById(R.id.dismiss_button);
|
||||
mDismissButton.setOnClickListener(this);
|
||||
|
||||
if (!mPowerUsageFeatureProvider.isBatteryTipsFeedbackEnabled()) {
|
||||
return;
|
||||
}
|
||||
view.findViewById(R.id.tips_card)
|
||||
.setBackgroundResource(R.drawable.battery_tips_half_rounded_top_bg);
|
||||
view.findViewById(R.id.feedback_card).setVisibility(View.VISIBLE);
|
||||
|
||||
mThumbUpButton = (ImageButton) view.findViewById(R.id.thumb_up);
|
||||
mThumbUpButton.setOnClickListener(this);
|
||||
mThumbDownButton = (ImageButton) view.findViewById(R.id.thumb_down);
|
||||
mThumbDownButton.setOnClickListener(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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.batteryusage;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
/** Controls the update for battery tips card */
|
||||
public class BatteryTipsController extends BasePreferenceController {
|
||||
|
||||
private static final String TAG = "BatteryTipsController";
|
||||
private static final String ROOT_PREFERENCE_KEY = "battery_tips_category";
|
||||
private static final String CARD_PREFERENCE_KEY = "battery_tips_card";
|
||||
|
||||
private final PowerUsageFeatureProvider mPowerUsageFeatureProvider;
|
||||
|
||||
private Context mPrefContext;
|
||||
private BatteryTipsCardPreference mCardPreference;
|
||||
|
||||
public BatteryTipsController(Context context) {
|
||||
super(context, ROOT_PREFERENCE_KEY);
|
||||
mPowerUsageFeatureProvider = FeatureFactory.getFactory(context)
|
||||
.getPowerUsageFeatureProvider(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPrefContext = screen.getContext();
|
||||
mCardPreference = screen.findPreference(CARD_PREFERENCE_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the card visibility and contents.
|
||||
* @param title a string not extend 2 lines.
|
||||
* @param summary a string not extend 10 lines.
|
||||
*/
|
||||
// TODO: replace parameters with SettingsAnomaly Data Proto
|
||||
public void handleBatteryTipsCardUpdated(String title, String summary) {
|
||||
if (!mPowerUsageFeatureProvider.isBatteryTipsEnabled()) {
|
||||
mCardPreference.setVisible(false);
|
||||
return;
|
||||
}
|
||||
if (title == null || summary == null) {
|
||||
mCardPreference.setVisible(false);
|
||||
return;
|
||||
}
|
||||
mCardPreference.setTitle(title);
|
||||
mCardPreference.setSummary(summary);
|
||||
mCardPreference.setVisible(true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -83,6 +83,10 @@ public final class BootBroadcastReceiver extends BroadcastReceiver {
|
||||
recheckIntent.setClass(context, BootBroadcastReceiver.class);
|
||||
final long delayedTime = getRescheduleTimeForBootAction(context);
|
||||
mHandler.postDelayed(() -> context.sendBroadcast(recheckIntent), delayedTime);
|
||||
|
||||
// Refreshes the usage source from UsageStatsManager when booting.
|
||||
DatabaseUtils.removeUsageSource(context);
|
||||
|
||||
BatteryUsageLogUtils.writeLog(context, Action.RECHECK_JOB, "delay:" + delayedTime);
|
||||
} else if (ACTION_SETUP_WIZARD_FINISHED.equals(action)) {
|
||||
ElapsedTimeUtils.storeSuwFinishedTimestamp(context, System.currentTimeMillis());
|
||||
|
||||
@@ -17,7 +17,6 @@ package com.android.settings.fuelgauge.batteryusage;
|
||||
|
||||
import android.annotation.IntDef;
|
||||
import android.annotation.Nullable;
|
||||
import android.app.usage.IUsageStatsManager;
|
||||
import android.app.usage.UsageEvents.Event;
|
||||
import android.app.usage.UsageStatsManager;
|
||||
import android.content.ContentValues;
|
||||
@@ -27,7 +26,6 @@ import android.database.Cursor;
|
||||
import android.os.BatteryUsageStats;
|
||||
import android.os.Build;
|
||||
import android.os.LocaleList;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserHandle;
|
||||
import android.text.TextUtils;
|
||||
import android.text.format.DateFormat;
|
||||
@@ -67,6 +65,12 @@ public final class ConvertUtils {
|
||||
public static final int CONSUMER_TYPE_USER_BATTERY = 2;
|
||||
public static final int CONSUMER_TYPE_SYSTEM_BATTERY = 3;
|
||||
|
||||
public static final int DEFAULT_USAGE_SOURCE = UsageStatsManager.USAGE_SOURCE_CURRENT_ACTIVITY;
|
||||
public static final int EMPTY_USAGE_SOURCE = -1;
|
||||
|
||||
@VisibleForTesting
|
||||
static int sUsageSource = EMPTY_USAGE_SOURCE;
|
||||
|
||||
private ConvertUtils() {
|
||||
}
|
||||
|
||||
@@ -181,8 +185,7 @@ public final class ConvertUtils {
|
||||
/** Converts to {@link AppUsageEvent} from {@link Event} */
|
||||
@Nullable
|
||||
public static AppUsageEvent convertToAppUsageEvent(
|
||||
Context context, final IUsageStatsManager usageStatsManager, final Event event,
|
||||
final long userId) {
|
||||
Context context, final Event event, final long userId) {
|
||||
final String packageName = event.getPackageName();
|
||||
if (packageName == null) {
|
||||
// See b/190609174: Event package names should never be null, but sometimes they are.
|
||||
@@ -207,7 +210,7 @@ public final class ConvertUtils {
|
||||
}
|
||||
|
||||
final String effectivePackageName =
|
||||
getEffectivePackageName(usageStatsManager, packageName, taskRootPackageName);
|
||||
getEffectivePackageName(context, packageName, taskRootPackageName);
|
||||
try {
|
||||
final long uid = context
|
||||
.getPackageManager()
|
||||
@@ -323,9 +326,8 @@ public final class ConvertUtils {
|
||||
*/
|
||||
@VisibleForTesting
|
||||
static String getEffectivePackageName(
|
||||
final IUsageStatsManager usageStatsManager, final String packageName,
|
||||
final String taskRootPackageName) {
|
||||
int usageSource = getUsageSource(usageStatsManager);
|
||||
Context context, final String packageName, final String taskRootPackageName) {
|
||||
final int usageSource = getUsageSource(context);
|
||||
switch (usageSource) {
|
||||
case UsageStatsManager.USAGE_SOURCE_TASK_ROOT_ACTIVITY:
|
||||
return !TextUtils.isEmpty(taskRootPackageName)
|
||||
@@ -370,18 +372,11 @@ public final class ConvertUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns what App Usage Observers will consider the source of usage for an activity.
|
||||
*
|
||||
* @see UsageStatsManager#getUsageSource()
|
||||
*/
|
||||
private static int getUsageSource(final IUsageStatsManager usageStatsManager) {
|
||||
try {
|
||||
return usageStatsManager.getUsageSource();
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "Failed to getUsageSource", e);
|
||||
return UsageStatsManager.USAGE_SOURCE_CURRENT_ACTIVITY;
|
||||
private static int getUsageSource(Context context) {
|
||||
if (sUsageSource == EMPTY_USAGE_SOURCE) {
|
||||
sUsageSource = DatabaseUtils.getUsageSource(context);
|
||||
}
|
||||
return sUsageSource;
|
||||
}
|
||||
|
||||
private static AppUsageEventType getAppUsageEventType(final int eventType) {
|
||||
|
||||
@@ -397,8 +397,8 @@ public class DataProcessManager {
|
||||
}
|
||||
// Generates the indexed AppUsagePeriod list data for each corresponding time slot for
|
||||
// further use.
|
||||
mAppUsagePeriodMap = DataProcessor.generateAppUsagePeriodMap(mRawStartTimestamp,
|
||||
mHourlyBatteryLevelsPerDay, mAppUsageEventList, mBatteryEventList);
|
||||
mAppUsagePeriodMap = DataProcessor.generateAppUsagePeriodMap(
|
||||
mContext, mHourlyBatteryLevelsPerDay, mAppUsageEventList, mBatteryEventList);
|
||||
}
|
||||
|
||||
private void tryToGenerateFinalDataAndApplyCallback() {
|
||||
|
||||
@@ -32,7 +32,6 @@ import android.os.BatteryUsageStats;
|
||||
import android.os.BatteryUsageStatsQuery;
|
||||
import android.os.Process;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.os.UidBatteryConsumer;
|
||||
import android.os.UserBatteryConsumer;
|
||||
import android.os.UserHandle;
|
||||
@@ -78,8 +77,6 @@ public final class DataProcessor {
|
||||
private static final int MIN_DAILY_DATA_SIZE = 2;
|
||||
private static final int MIN_TIMESTAMP_DATA_SIZE = 2;
|
||||
private static final int MAX_DIFF_SECONDS_OF_UPPER_TIMESTAMP = 5;
|
||||
// Maximum total time value for each hourly slot cumulative data at most 2 hours.
|
||||
private static final float TOTAL_HOURLY_TIME_THRESHOLD = DateUtils.HOUR_IN_MILLIS * 2;
|
||||
private static final long MIN_TIME_SLOT = DateUtils.HOUR_IN_MILLIS * 2;
|
||||
private static final String MEDIASERVER_PACKAGE_NAME = "mediaserver";
|
||||
private static final String ANDROID_CORE_APPS_SHARED_USER_ID = "android.uid.shared";
|
||||
@@ -111,11 +108,6 @@ public final class DataProcessor {
|
||||
@VisibleForTesting
|
||||
static Set<String> sTestSystemAppsPackageNames;
|
||||
|
||||
@VisibleForTesting
|
||||
static IUsageStatsManager sUsageStatsManager =
|
||||
IUsageStatsManager.Stub.asInterface(
|
||||
ServiceManager.getService(Context.USAGE_STATS_SERVICE));
|
||||
|
||||
public static final String CURRENT_TIME_BATTERY_HISTORY_PLACEHOLDER =
|
||||
"CURRENT_TIME_BATTERY_HISTORY_PLACEHOLDER";
|
||||
|
||||
@@ -271,7 +263,7 @@ public final class DataProcessor {
|
||||
@Nullable
|
||||
public static Map<Integer, Map<Integer, Map<Long, Map<String, List<AppUsagePeriod>>>>>
|
||||
generateAppUsagePeriodMap(
|
||||
final long rawStartTimestamp,
|
||||
Context context,
|
||||
final List<BatteryLevelData.PeriodBatteryLevelData> hourlyBatteryLevelsPerDay,
|
||||
final List<AppUsageEvent> appUsageEventList,
|
||||
final List<BatteryEvent> batteryEventList) {
|
||||
@@ -305,7 +297,7 @@ public final class DataProcessor {
|
||||
// The value could be null when there is no data in the hourly slot.
|
||||
dailyMap.put(
|
||||
hourlyIndex,
|
||||
buildAppUsagePeriodList(hourlyAppUsageEventList, batteryEventList,
|
||||
buildAppUsagePeriodList(context, hourlyAppUsageEventList, batteryEventList,
|
||||
startTimestamp, endTimestamp));
|
||||
}
|
||||
}
|
||||
@@ -346,8 +338,7 @@ public final class DataProcessor {
|
||||
break;
|
||||
}
|
||||
final AppUsageEvent appUsageEvent =
|
||||
ConvertUtils.convertToAppUsageEvent(
|
||||
context, sUsageStatsManager, event, userId);
|
||||
ConvertUtils.convertToAppUsageEvent(context, event, userId);
|
||||
if (appUsageEvent != null) {
|
||||
numEventsFetched++;
|
||||
appUsageEventList.add(appUsageEvent);
|
||||
@@ -661,8 +652,8 @@ public final class DataProcessor {
|
||||
@VisibleForTesting
|
||||
@Nullable
|
||||
static Map<Long, Map<String, List<AppUsagePeriod>>> buildAppUsagePeriodList(
|
||||
final List<AppUsageEvent> appUsageEvents, final List<BatteryEvent> batteryEventList,
|
||||
final long startTime, final long endTime) {
|
||||
Context context, final List<AppUsageEvent> appUsageEvents,
|
||||
final List<BatteryEvent> batteryEventList, final long startTime, final long endTime) {
|
||||
if (appUsageEvents.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
@@ -702,7 +693,7 @@ public final class DataProcessor {
|
||||
final AppUsageEvent firstEvent = usageEvents.get(0);
|
||||
final long eventUserId = firstEvent.getUserId();
|
||||
final String packageName = getEffectivePackageName(
|
||||
sUsageStatsManager,
|
||||
context,
|
||||
firstEvent.getPackageName(),
|
||||
firstEvent.getTaskRootPackageName());
|
||||
usageEvents.addAll(deviceEvents);
|
||||
@@ -975,7 +966,7 @@ public final class DataProcessor {
|
||||
final long startTime = DatabaseUtils.getAppUsageStartTimestampOfUser(
|
||||
context, userID, earliestTimestamp);
|
||||
return loadAppUsageEventsForUserFromService(
|
||||
sUsageStatsManager, startTime, now, userID, callingPackage);
|
||||
DatabaseUtils.sUsageStatsManager, startTime, now, userID, callingPackage);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
|
||||
package com.android.settings.fuelgauge.batteryusage;
|
||||
import android.app.usage.IUsageStatsManager;
|
||||
import android.app.usage.UsageStatsManager;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
@@ -28,6 +30,8 @@ import android.os.BatteryManager;
|
||||
import android.os.BatteryUsageStats;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.os.SystemClock;
|
||||
import android.os.UserManager;
|
||||
import android.util.Log;
|
||||
@@ -63,6 +67,7 @@ public final class DatabaseUtils {
|
||||
static final int DATA_RETENTION_INTERVAL_DAY = 9;
|
||||
static final String KEY_LAST_LOAD_FULL_CHARGE_TIME = "last_load_full_charge_time";
|
||||
static final String KEY_LAST_UPLOAD_FULL_CHARGE_TIME = "last_upload_full_charge_time";
|
||||
static final String KEY_LAST_USAGE_SOURCE = "last_usage_source";
|
||||
|
||||
/** An authority name of the battery content provider. */
|
||||
public static final String AUTHORITY = "com.android.settings.battery.usage.provider";
|
||||
@@ -74,8 +79,6 @@ public final class DatabaseUtils {
|
||||
public static final String BATTERY_STATE_TABLE = "BatteryState";
|
||||
/** A path name for app usage latest timestamp query. */
|
||||
public static final String APP_USAGE_LATEST_TIMESTAMP_PATH = "appUsageLatestTimestamp";
|
||||
/** A class name for battery usage data provider. */
|
||||
public static final String SETTINGS_PACKAGE_PATH = "com.android.settings";
|
||||
/** Key for query parameter timestamp used in BATTERY_CONTENT_URI **/
|
||||
public static final String QUERY_KEY_TIMESTAMP = "timestamp";
|
||||
/** Key for query parameter userid used in APP_USAGE_EVENT_URI **/
|
||||
@@ -114,6 +117,11 @@ public final class DatabaseUtils {
|
||||
@VisibleForTesting
|
||||
static Supplier<Cursor> sFakeSupplier;
|
||||
|
||||
@VisibleForTesting
|
||||
static IUsageStatsManager sUsageStatsManager =
|
||||
IUsageStatsManager.Stub.asInterface(
|
||||
ServiceManager.getService(Context.USAGE_STATS_SERVICE));
|
||||
|
||||
private DatabaseUtils() {
|
||||
}
|
||||
|
||||
@@ -468,6 +476,37 @@ public final class DatabaseUtils {
|
||||
SHARED_PREFS_FILE, Context.MODE_PRIVATE);
|
||||
}
|
||||
|
||||
static void removeUsageSource(Context context) {
|
||||
final SharedPreferences sharedPreferences = getSharedPreferences(context);
|
||||
if (sharedPreferences != null && sharedPreferences.contains(KEY_LAST_USAGE_SOURCE)) {
|
||||
sharedPreferences.edit().remove(KEY_LAST_USAGE_SOURCE).apply();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns what App Usage Observers will consider the source of usage for an activity.
|
||||
*
|
||||
* @see UsageStatsManager#getUsageSource()
|
||||
*/
|
||||
static int getUsageSource(Context context) {
|
||||
final SharedPreferences sharedPreferences = getSharedPreferences(context);
|
||||
if (sharedPreferences != null && sharedPreferences.contains(KEY_LAST_USAGE_SOURCE)) {
|
||||
return sharedPreferences
|
||||
.getInt(KEY_LAST_USAGE_SOURCE, ConvertUtils.DEFAULT_USAGE_SOURCE);
|
||||
}
|
||||
int usageSource = ConvertUtils.DEFAULT_USAGE_SOURCE;
|
||||
|
||||
try {
|
||||
usageSource = sUsageStatsManager.getUsageSource();
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "Failed to getUsageSource", e);
|
||||
}
|
||||
if (sharedPreferences != null) {
|
||||
sharedPreferences.edit().putInt(KEY_LAST_USAGE_SOURCE, usageSource).apply();
|
||||
}
|
||||
return usageSource;
|
||||
}
|
||||
|
||||
static void recordDateTime(Context context, String preferenceKey) {
|
||||
final SharedPreferences sharedPreferences = getSharedPreferences(context);
|
||||
if (sharedPreferences != null) {
|
||||
@@ -564,7 +603,7 @@ public final class DatabaseUtils {
|
||||
|
||||
private static Map<Long, Map<String, BatteryHistEntry>> loadHistoryMapFromContentProvider(
|
||||
Context context, Uri batteryStateUri) {
|
||||
context = DatabaseUtils.getParentContext(context);
|
||||
context = getParentContext(context);
|
||||
if (context == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,8 @@ import androidx.loader.content.Loader;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.fuelgauge.BatteryBroadcastReceiver;
|
||||
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
@@ -143,6 +145,16 @@ public class PowerUsageAdvanced extends PowerUsageBase {
|
||||
controllers.add(screenOnTimeController);
|
||||
controllers.add(batteryUsageBreakdownController);
|
||||
setBatteryChartPreferenceController();
|
||||
|
||||
final PowerUsageFeatureProvider powerUsageFeatureProvider =
|
||||
FeatureFactory.getFactory(context).getPowerUsageFeatureProvider(context);
|
||||
if (powerUsageFeatureProvider.isBatteryTipsEnabled()) {
|
||||
BatteryTipsController batteryTipsController = new BatteryTipsController(context);
|
||||
mBatteryChartPreferenceController.setOnBatteryTipsUpdatedListener(
|
||||
batteryTipsController::handleBatteryTipsCardUpdated);
|
||||
controllers.add(batteryTipsController);
|
||||
}
|
||||
|
||||
return controllers;
|
||||
}
|
||||
|
||||
|
||||
@@ -523,6 +523,7 @@ public class ChooseLockPassword extends SettingsActivity {
|
||||
setupPasswordRequirementsView(headerLayout);
|
||||
|
||||
mPasswordRestrictionView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
mPasswordRestrictionView.setAccessibilityLiveRegion(ACCESSIBILITY_LIVE_REGION_POLITE);
|
||||
mPasswordEntry = view.findViewById(R.id.password_entry);
|
||||
mPasswordEntry.setOnEditorActionListener(this);
|
||||
mPasswordEntry.addTextChangedListener(this);
|
||||
|
||||
@@ -67,6 +67,15 @@ public class PowerUsageFeatureProviderImplTest {
|
||||
assertThat(mPowerFeatureProvider.isBatteryUsageEnabled()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsBatteryTipsEnabled_returnFalse() {
|
||||
assertThat(mPowerFeatureProvider.isBatteryTipsEnabled()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsBatteryTipsFeedbackEnabled_returnTrue() {
|
||||
assertThat(mPowerFeatureProvider.isBatteryTipsFeedbackEnabled()).isTrue();
|
||||
}
|
||||
@Test
|
||||
public void testGetBatteryUsageListConsumePowerThreshold_return0() {
|
||||
assertThat(mPowerFeatureProvider.getBatteryUsageListConsumePowerThreshold()).isEqualTo(0.0);
|
||||
|
||||
@@ -85,7 +85,7 @@ public final class IncompatibleChargerTipTest {
|
||||
@Test
|
||||
public void getIcon_showIcon() {
|
||||
assertThat(mIncompatibleChargerTip.getIconId())
|
||||
.isEqualTo(R.drawable.ic_battery_alert_theme);
|
||||
.isEqualTo(R.drawable.ic_battery_charger);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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.batteryusage;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public final class BatteryTipsCardPreferenceTest {
|
||||
|
||||
private Context mContext;
|
||||
private BatteryTipsCardPreference mBatteryTipsCardPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mBatteryTipsCardPreference = new BatteryTipsCardPreference(mContext, /*attrs=*/ null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructor_returnExpectedResult() {
|
||||
assertThat(mBatteryTipsCardPreference.getLayoutResource()).isEqualTo(
|
||||
R.layout.battery_tips_card);
|
||||
}
|
||||
}
|
||||
@@ -22,8 +22,10 @@ import static org.robolectric.Shadows.shadowOf;
|
||||
|
||||
import android.app.AlarmManager;
|
||||
import android.app.Application;
|
||||
import android.app.usage.UsageStatsManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
@@ -40,7 +42,6 @@ import org.robolectric.Shadows;
|
||||
import org.robolectric.shadows.ShadowAlarmManager;
|
||||
|
||||
import java.time.Clock;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -65,10 +66,12 @@ public final class BootBroadcastReceiverTest {
|
||||
BatteryTestUtils.insertDataToBatteryStateTable(
|
||||
mContext, Clock.systemUTC().millis(), "com.android.systemui");
|
||||
mDao = database.batteryStateDao();
|
||||
clearSharedPreferences();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
clearSharedPreferences();
|
||||
mPeriodicJobManager.reset();
|
||||
}
|
||||
|
||||
@@ -82,8 +85,21 @@ public final class BootBroadcastReceiverTest {
|
||||
|
||||
@Test
|
||||
public void onReceive_withBootCompletedIntent_refreshesJob() {
|
||||
final SharedPreferences sharedPreferences = DatabaseUtils.getSharedPreferences(mContext);
|
||||
sharedPreferences
|
||||
.edit()
|
||||
.putInt(DatabaseUtils.KEY_LAST_USAGE_SOURCE,
|
||||
UsageStatsManager.USAGE_SOURCE_CURRENT_ACTIVITY)
|
||||
.apply();
|
||||
|
||||
mReceiver.onReceive(mContext, new Intent(Intent.ACTION_BOOT_COMPLETED));
|
||||
|
||||
assertThat(mShadowAlarmManager.peekNextScheduledAlarm()).isNotNull();
|
||||
assertThat(
|
||||
DatabaseUtils
|
||||
.getSharedPreferences(mContext)
|
||||
.contains(DatabaseUtils.KEY_LAST_USAGE_SOURCE))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -133,15 +149,7 @@ public final class BootBroadcastReceiverTest {
|
||||
BootBroadcastReceiver.ACTION_PERIODIC_JOB_RECHECK);
|
||||
}
|
||||
|
||||
private void insertExpiredData(int shiftDay) {
|
||||
final long expiredTimeInMs =
|
||||
Clock.systemUTC().millis() - Duration.ofDays(shiftDay).toMillis();
|
||||
BatteryTestUtils.insertDataToBatteryStateTable(
|
||||
mContext, expiredTimeInMs - 1, "com.android.systemui");
|
||||
BatteryTestUtils.insertDataToBatteryStateTable(
|
||||
mContext, expiredTimeInMs, "com.android.systemui");
|
||||
// Ensures the testing environment is correct.
|
||||
assertThat(mDao.getAllAfter(0)).hasSize(3);
|
||||
private void clearSharedPreferences() {
|
||||
DatabaseUtils.getSharedPreferences(mContext).edit().clear().apply();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.usage.IUsageStatsManager;
|
||||
import android.app.usage.UsageEvents;
|
||||
import android.app.usage.UsageEvents.Event;
|
||||
import android.content.ContentValues;
|
||||
@@ -35,7 +34,6 @@ import android.database.MatrixCursor;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.BatteryUsageStats;
|
||||
import android.os.LocaleList;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserHandle;
|
||||
|
||||
import com.android.settings.fuelgauge.batteryusage.db.AppUsageEventEntity;
|
||||
@@ -62,14 +60,13 @@ public final class ConvertUtilsTest {
|
||||
@Mock
|
||||
private BatteryUsageStats mBatteryUsageStats;
|
||||
@Mock
|
||||
private IUsageStatsManager mUsageStatsManager;
|
||||
@Mock
|
||||
private BatteryEntry mMockBatteryEntry;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
ConvertUtils.sUsageSource = ConvertUtils.EMPTY_USAGE_SOURCE;
|
||||
when(mContext.getPackageManager()).thenReturn(mMockPackageManager);
|
||||
}
|
||||
|
||||
@@ -302,7 +299,7 @@ public final class ConvertUtilsTest {
|
||||
|
||||
final long userId = 2;
|
||||
final AppUsageEvent appUsageEvent = ConvertUtils.convertToAppUsageEvent(
|
||||
mContext, mUsageStatsManager, event, userId);
|
||||
mContext, event, userId);
|
||||
assertThat(appUsageEvent.getTimestamp()).isEqualTo(101L);
|
||||
assertThat(appUsageEvent.getType()).isEqualTo(AppUsageEventType.ACTIVITY_RESUMED);
|
||||
assertThat(appUsageEvent.getPackageName()).isEqualTo("com.android.settings1");
|
||||
@@ -322,8 +319,8 @@ public final class ConvertUtilsTest {
|
||||
when(mMockPackageManager.getPackageUidAsUser(any(), anyInt())).thenReturn(1001);
|
||||
|
||||
final long userId = 1;
|
||||
final AppUsageEvent appUsageEvent = ConvertUtils.convertToAppUsageEvent(
|
||||
mContext, mUsageStatsManager, event, userId);
|
||||
final AppUsageEvent appUsageEvent =
|
||||
ConvertUtils.convertToAppUsageEvent(mContext, event, userId);
|
||||
assertThat(appUsageEvent.getTimestamp()).isEqualTo(101L);
|
||||
assertThat(appUsageEvent.getType()).isEqualTo(AppUsageEventType.DEVICE_SHUTDOWN);
|
||||
assertThat(appUsageEvent.getPackageName()).isEqualTo("com.android.settings1");
|
||||
@@ -338,8 +335,8 @@ public final class ConvertUtilsTest {
|
||||
final Event event = new Event();
|
||||
event.mPackage = null;
|
||||
|
||||
final AppUsageEvent appUsageEvent = ConvertUtils.convertToAppUsageEvent(
|
||||
mContext, mUsageStatsManager, event, /*userId=*/ 0);
|
||||
final AppUsageEvent appUsageEvent =
|
||||
ConvertUtils.convertToAppUsageEvent(mContext, event, /*userId=*/ 0);
|
||||
|
||||
assertThat(appUsageEvent).isNull();
|
||||
}
|
||||
@@ -354,8 +351,8 @@ public final class ConvertUtilsTest {
|
||||
.thenThrow(new PackageManager.NameNotFoundException());
|
||||
|
||||
final long userId = 1;
|
||||
final AppUsageEvent appUsageEvent = ConvertUtils.convertToAppUsageEvent(
|
||||
mContext, mUsageStatsManager, event, userId);
|
||||
final AppUsageEvent appUsageEvent =
|
||||
ConvertUtils.convertToAppUsageEvent(mContext, event, userId);
|
||||
|
||||
assertThat(appUsageEvent).isNull();
|
||||
}
|
||||
@@ -450,51 +447,47 @@ public final class ConvertUtilsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEffectivePackageName_currentActivity_returnPackageName() throws RemoteException {
|
||||
when(mUsageStatsManager.getUsageSource()).thenReturn(USAGE_SOURCE_CURRENT_ACTIVITY);
|
||||
public void getEffectivePackageName_currentActivity_returnPackageName() {
|
||||
ConvertUtils.sUsageSource = USAGE_SOURCE_CURRENT_ACTIVITY;
|
||||
final String packageName = "com.android.settings1";
|
||||
final String taskRootPackageName = "com.android.settings2";
|
||||
|
||||
assertThat(ConvertUtils.getEffectivePackageName(
|
||||
mUsageStatsManager, packageName, taskRootPackageName))
|
||||
mContext, packageName, taskRootPackageName))
|
||||
.isEqualTo(packageName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEffectivePackageName_usageSourceThrowException_returnPackageName()
|
||||
throws RemoteException {
|
||||
when(mUsageStatsManager.getUsageSource()).thenThrow(new RemoteException());
|
||||
public void getEffectivePackageName_emptyUsageSource_returnPackageName() {
|
||||
final String packageName = "com.android.settings1";
|
||||
final String taskRootPackageName = "com.android.settings2";
|
||||
|
||||
assertThat(ConvertUtils.getEffectivePackageName(
|
||||
mUsageStatsManager, packageName, taskRootPackageName))
|
||||
mContext, packageName, taskRootPackageName))
|
||||
.isEqualTo(packageName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEffectivePackageName_rootActivity_returnTaskRootPackageName()
|
||||
throws RemoteException {
|
||||
when(mUsageStatsManager.getUsageSource()).thenReturn(USAGE_SOURCE_TASK_ROOT_ACTIVITY);
|
||||
public void getEffectivePackageName_rootActivity_returnTaskRootPackageName() {
|
||||
ConvertUtils.sUsageSource = USAGE_SOURCE_TASK_ROOT_ACTIVITY;
|
||||
final String packageName = "com.android.settings1";
|
||||
final String taskRootPackageName = "com.android.settings2";
|
||||
|
||||
assertThat(ConvertUtils.getEffectivePackageName(
|
||||
mUsageStatsManager, packageName, taskRootPackageName))
|
||||
mContext, packageName, taskRootPackageName))
|
||||
.isEqualTo(taskRootPackageName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEffectivePackageName_nullOrEmptyTaskRoot_returnPackageName()
|
||||
throws RemoteException {
|
||||
when(mUsageStatsManager.getUsageSource()).thenReturn(USAGE_SOURCE_TASK_ROOT_ACTIVITY);
|
||||
public void getEffectivePackageName_nullOrEmptyTaskRoot_returnPackageName() {
|
||||
ConvertUtils.sUsageSource = USAGE_SOURCE_TASK_ROOT_ACTIVITY;
|
||||
final String packageName = "com.android.settings1";
|
||||
|
||||
assertThat(ConvertUtils.getEffectivePackageName(
|
||||
mUsageStatsManager, packageName, /*taskRootPackageName=*/ null))
|
||||
mContext, packageName, /*taskRootPackageName=*/ null))
|
||||
.isEqualTo(packageName);
|
||||
assertThat(ConvertUtils.getEffectivePackageName(
|
||||
mUsageStatsManager, packageName, /*taskRootPackageName=*/ ""))
|
||||
mContext, packageName, /*taskRootPackageName=*/ ""))
|
||||
.isEqualTo(packageName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public final class DataProcessManagerTest {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
DataProcessor.sUsageStatsManager = mUsageStatsManager;
|
||||
DatabaseUtils.sUsageStatsManager = mUsageStatsManager;
|
||||
doReturn(mContext).when(mContext).getApplicationContext();
|
||||
doReturn(mUserManager)
|
||||
.when(mContext)
|
||||
|
||||
@@ -93,7 +93,7 @@ public final class DataProcessorTest {
|
||||
mPowerUsageFeatureProvider = mFeatureFactory.powerUsageFeatureProvider;
|
||||
|
||||
DataProcessor.sTestSystemAppsPackageNames = Set.of();
|
||||
DataProcessor.sUsageStatsManager = mUsageStatsManager;
|
||||
DatabaseUtils.sUsageStatsManager = mUsageStatsManager;
|
||||
doReturn(mIntent).when(mContext).registerReceiver(
|
||||
isA(BroadcastReceiver.class), isA(IntentFilter.class));
|
||||
doReturn(100).when(mIntent).getIntExtra(eq(BatteryManager.EXTRA_SCALE), anyInt());
|
||||
@@ -249,7 +249,7 @@ public final class DataProcessorTest {
|
||||
|
||||
final Map<Integer, Map<Integer, Map<Long, Map<String, List<AppUsagePeriod>>>>> periodMap =
|
||||
DataProcessor.generateAppUsagePeriodMap(
|
||||
14400000L, hourlyBatteryLevelsPerDay, appUsageEventList, new ArrayList<>());
|
||||
mContext, hourlyBatteryLevelsPerDay, appUsageEventList, new ArrayList<>());
|
||||
|
||||
assertThat(periodMap).hasSize(3);
|
||||
// Day 1
|
||||
@@ -287,7 +287,8 @@ public final class DataProcessorTest {
|
||||
hourlyBatteryLevelsPerDay.add(
|
||||
new BatteryLevelData.PeriodBatteryLevelData(new ArrayList<>(), new ArrayList<>()));
|
||||
assertThat(DataProcessor.generateAppUsagePeriodMap(
|
||||
0L, hourlyBatteryLevelsPerDay, new ArrayList<>(), new ArrayList<>())).isNull();
|
||||
mContext, hourlyBatteryLevelsPerDay, new ArrayList<>(), new ArrayList<>()))
|
||||
.isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1644,7 +1645,7 @@ public final class DataProcessorTest {
|
||||
|
||||
final Map<Long, Map<String, List<AppUsagePeriod>>> appUsagePeriodMap =
|
||||
DataProcessor.buildAppUsagePeriodList(
|
||||
appUsageEvents, new ArrayList<>(), 0, 5);
|
||||
mContext, appUsageEvents, new ArrayList<>(), 0, 5);
|
||||
|
||||
assertThat(appUsagePeriodMap).hasSize(2);
|
||||
final Map<String, List<AppUsagePeriod>> userMap1 = appUsagePeriodMap.get(1L);
|
||||
@@ -1668,7 +1669,7 @@ public final class DataProcessorTest {
|
||||
@Test
|
||||
public void buildAppUsagePeriodList_emptyEventList_returnNull() {
|
||||
assertThat(DataProcessor.buildAppUsagePeriodList(
|
||||
new ArrayList<>(), new ArrayList<>(), 0, 1)).isNull();
|
||||
mContext, new ArrayList<>(), new ArrayList<>(), 0, 1)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1680,7 +1681,7 @@ public final class DataProcessorTest {
|
||||
AppUsageEventType.DEVICE_SHUTDOWN, /*timestamp=*/ 2));
|
||||
|
||||
assertThat(DataProcessor.buildAppUsagePeriodList(
|
||||
appUsageEvents, new ArrayList<>(), 0, 3)).isNull();
|
||||
mContext, appUsageEvents, new ArrayList<>(), 0, 3)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
|
||||
package com.android.settings.fuelgauge.batteryusage;
|
||||
|
||||
import static android.app.usage.UsageStatsManager.USAGE_SOURCE_CURRENT_ACTIVITY;
|
||||
import static android.app.usage.UsageStatsManager.USAGE_SOURCE_TASK_ROOT_ACTIVITY;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
@@ -23,15 +26,19 @@ import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.usage.IUsageStatsManager;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.database.MatrixCursor;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.BatteryUsageStats;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
|
||||
@@ -67,6 +74,7 @@ public final class DatabaseUtilsTest {
|
||||
@Mock private BatteryEntry mMockBatteryEntry2;
|
||||
@Mock private BatteryEntry mMockBatteryEntry3;
|
||||
@Mock private Context mMockContext;
|
||||
@Mock private IUsageStatsManager mUsageStatsManager;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -77,6 +85,7 @@ public final class DatabaseUtilsTest {
|
||||
doReturn(mPackageManager).when(mMockContext).getPackageManager();
|
||||
doReturn(mPackageManager).when(mContext).getPackageManager();
|
||||
DatabaseUtils.getSharedPreferences(mContext).edit().clear().apply();
|
||||
DatabaseUtils.sUsageStatsManager = mUsageStatsManager;
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -422,6 +431,71 @@ public final class DatabaseUtilsTest {
|
||||
assertThat(batteryHistMap).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeUsageSource_hasNoData() {
|
||||
DatabaseUtils.removeUsageSource(mContext);
|
||||
assertThat(
|
||||
DatabaseUtils
|
||||
.getSharedPreferences(mContext)
|
||||
.contains(DatabaseUtils.KEY_LAST_USAGE_SOURCE))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeUsageSource_hasData_deleteUsageSource() {
|
||||
final SharedPreferences sharedPreferences = DatabaseUtils.getSharedPreferences(mContext);
|
||||
sharedPreferences
|
||||
.edit()
|
||||
.putInt(DatabaseUtils.KEY_LAST_USAGE_SOURCE, USAGE_SOURCE_TASK_ROOT_ACTIVITY)
|
||||
.apply();
|
||||
|
||||
DatabaseUtils.removeUsageSource(mContext);
|
||||
|
||||
assertThat(
|
||||
DatabaseUtils
|
||||
.getSharedPreferences(mContext)
|
||||
.contains(DatabaseUtils.KEY_LAST_USAGE_SOURCE))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUsageSource_hasData() {
|
||||
final SharedPreferences sharedPreferences = DatabaseUtils.getSharedPreferences(mContext);
|
||||
sharedPreferences
|
||||
.edit()
|
||||
.putInt(DatabaseUtils.KEY_LAST_USAGE_SOURCE, USAGE_SOURCE_TASK_ROOT_ACTIVITY)
|
||||
.apply();
|
||||
|
||||
assertThat(DatabaseUtils.getUsageSource(mContext))
|
||||
.isEqualTo(USAGE_SOURCE_TASK_ROOT_ACTIVITY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUsageSource_notHasData_writeLoadedData() throws RemoteException {
|
||||
when(mUsageStatsManager.getUsageSource()).thenReturn(USAGE_SOURCE_TASK_ROOT_ACTIVITY);
|
||||
|
||||
assertThat(DatabaseUtils.getUsageSource(mContext))
|
||||
.isEqualTo(USAGE_SOURCE_TASK_ROOT_ACTIVITY);
|
||||
assertThat(
|
||||
DatabaseUtils
|
||||
.getSharedPreferences(mContext)
|
||||
.getInt(DatabaseUtils.KEY_LAST_USAGE_SOURCE, USAGE_SOURCE_CURRENT_ACTIVITY))
|
||||
.isEqualTo(USAGE_SOURCE_TASK_ROOT_ACTIVITY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUsageSource_throwException_writeDefaultData() throws RemoteException {
|
||||
when(mUsageStatsManager.getUsageSource()).thenThrow(new RemoteException());
|
||||
|
||||
assertThat(DatabaseUtils.getUsageSource(mContext))
|
||||
.isEqualTo(USAGE_SOURCE_CURRENT_ACTIVITY);
|
||||
assertThat(
|
||||
DatabaseUtils
|
||||
.getSharedPreferences(mContext)
|
||||
.getInt(DatabaseUtils.KEY_LAST_USAGE_SOURCE, USAGE_SOURCE_CURRENT_ACTIVITY))
|
||||
.isEqualTo(USAGE_SOURCE_CURRENT_ACTIVITY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void recordDateTime_writeDataIntoSharedPreferences() {
|
||||
final String preferenceKey = "test_preference_key";
|
||||
|
||||
Reference in New Issue
Block a user