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.content.Context;
20 import android.os.Parcel;
21 
22 import androidx.annotation.VisibleForTesting;
23 
24 import com.android.settings.fuelgauge.AdvancedPowerUsageDetail;
25 import com.android.settings.fuelgauge.batterytip.AppInfo;
26 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
27 
28 /**
29  * Tip to suggest user to remove app restriction. This is the empty tip and it is only used in
30  * {@link AdvancedPowerUsageDetail} to create dialog.
31  */
32 public class UnrestrictAppTip extends BatteryTip {
33     private AppInfo mAppInfo;
34 
UnrestrictAppTip(@tateType int state, AppInfo appInfo)35     public UnrestrictAppTip(@StateType int state, AppInfo appInfo) {
36         super(TipType.REMOVE_APP_RESTRICTION, state, true /* showDialog */);
37         mAppInfo = appInfo;
38     }
39 
40     @VisibleForTesting
UnrestrictAppTip(Parcel in)41     UnrestrictAppTip(Parcel in) {
42         super(in);
43         mAppInfo = in.readParcelable(getClass().getClassLoader());
44     }
45 
46     @Override
getTitle(Context context)47     public CharSequence getTitle(Context context) {
48         // Don't need title since this is an empty tip
49         return null;
50     }
51 
52     @Override
getSummary(Context context)53     public CharSequence getSummary(Context context) {
54         // Don't need summary since this is an empty tip
55         return null;
56     }
57 
58     @Override
getIconId()59     public int getIconId() {
60         return 0;
61     }
62 
getPackageName()63     public String getPackageName() {
64         return mAppInfo.packageName;
65     }
66 
67     @Override
updateState(BatteryTip tip)68     public void updateState(BatteryTip tip) {
69         mState = tip.mState;
70     }
71 
72     @Override
log(Context context, MetricsFeatureProvider metricsFeatureProvider)73     public void log(Context context, MetricsFeatureProvider metricsFeatureProvider) {
74         // Do nothing
75     }
76 
getUnrestrictAppInfo()77     public AppInfo getUnrestrictAppInfo() {
78         return mAppInfo;
79     }
80 
81     @Override
writeToParcel(Parcel dest, int flags)82     public void writeToParcel(Parcel dest, int flags) {
83         super.writeToParcel(dest, flags);
84         dest.writeParcelable(mAppInfo, flags);
85     }
86 
87     public static final Creator CREATOR =
88             new Creator() {
89                 public BatteryTip createFromParcel(Parcel in) {
90                     return new UnrestrictAppTip(in);
91                 }
92 
93                 public BatteryTip[] newArray(int size) {
94                     return new UnrestrictAppTip[size];
95                 }
96             };
97 }
98