• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settings.fuelgauge.batterytip.tips;
18 
19 import android.app.settings.SettingsEnums;
20 import android.content.Context;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 
24 import androidx.annotation.VisibleForTesting;
25 
26 import com.android.settings.R;
27 import com.android.settings.fuelgauge.batterytip.AppInfo;
28 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
29 
30 import java.util.List;
31 
32 /** Tip to show general summary about battery life */
33 public class HighUsageTip extends BatteryTip {
34 
35     private final long mLastFullChargeTimeMs;
36     @VisibleForTesting final List<AppInfo> mHighUsageAppList;
37 
HighUsageTip(long lastFullChargeTimeMs, List<AppInfo> appList)38     public HighUsageTip(long lastFullChargeTimeMs, List<AppInfo> appList) {
39         super(
40                 TipType.HIGH_DEVICE_USAGE,
41                 appList.isEmpty() ? StateType.INVISIBLE : StateType.NEW,
42                 true /* showDialog */);
43         mLastFullChargeTimeMs = lastFullChargeTimeMs;
44         mHighUsageAppList = appList;
45     }
46 
47     @VisibleForTesting
HighUsageTip(Parcel in)48     HighUsageTip(Parcel in) {
49         super(in);
50         mLastFullChargeTimeMs = in.readLong();
51         mHighUsageAppList = in.createTypedArrayList(AppInfo.CREATOR);
52     }
53 
54     @Override
writeToParcel(Parcel dest, int flags)55     public void writeToParcel(Parcel dest, int flags) {
56         super.writeToParcel(dest, flags);
57         dest.writeLong(mLastFullChargeTimeMs);
58         dest.writeTypedList(mHighUsageAppList);
59     }
60 
61     @Override
getTitle(Context context)62     public CharSequence getTitle(Context context) {
63         return context.getString(R.string.battery_tip_high_usage_title);
64     }
65 
66     @Override
getSummary(Context context)67     public CharSequence getSummary(Context context) {
68         return context.getString(R.string.battery_tip_high_usage_summary);
69     }
70 
71     @Override
getIconId()72     public int getIconId() {
73         return R.drawable.ic_perm_device_information_theme;
74     }
75 
76     @Override
updateState(BatteryTip tip)77     public void updateState(BatteryTip tip) {
78         mState = tip.mState;
79     }
80 
81     @Override
log(Context context, MetricsFeatureProvider metricsFeatureProvider)82     public void log(Context context, MetricsFeatureProvider metricsFeatureProvider) {
83         metricsFeatureProvider.action(context, SettingsEnums.ACTION_HIGH_USAGE_TIP, mState);
84         for (int i = 0, size = mHighUsageAppList.size(); i < size; i++) {
85             final AppInfo appInfo = mHighUsageAppList.get(i);
86             metricsFeatureProvider.action(
87                     context, SettingsEnums.ACTION_HIGH_USAGE_TIP_LIST, appInfo.packageName);
88         }
89     }
90 
getLastFullChargeTimeMs()91     public long getLastFullChargeTimeMs() {
92         return mLastFullChargeTimeMs;
93     }
94 
getHighUsageAppList()95     public List<AppInfo> getHighUsageAppList() {
96         return mHighUsageAppList;
97     }
98 
99     @Override
toString()100     public String toString() {
101         final StringBuilder stringBuilder = new StringBuilder(super.toString());
102         stringBuilder.append(" {");
103         for (int i = 0, size = mHighUsageAppList.size(); i < size; i++) {
104             final AppInfo appInfo = mHighUsageAppList.get(i);
105             stringBuilder.append(" " + appInfo.toString() + " ");
106         }
107         stringBuilder.append('}');
108 
109         return stringBuilder.toString();
110     }
111 
112     public static final Parcelable.Creator CREATOR =
113             new Parcelable.Creator() {
114                 public BatteryTip createFromParcel(Parcel in) {
115                     return new HighUsageTip(in);
116                 }
117 
118                 public BatteryTip[] newArray(int size) {
119                     return new HighUsageTip[size];
120                 }
121             };
122 }
123