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