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.actions; 18 19 import android.app.settings.SettingsEnums; 20 21 import androidx.annotation.VisibleForTesting; 22 23 import com.android.settings.core.InstrumentedPreferenceFragment; 24 import com.android.settings.fuelgauge.RestrictedAppDetails; 25 import com.android.settings.fuelgauge.batterytip.AnomalyDatabaseHelper; 26 import com.android.settings.fuelgauge.batterytip.AppInfo; 27 import com.android.settings.fuelgauge.batterytip.BatteryDatabaseManager; 28 import com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip; 29 import com.android.settingslib.utils.ThreadUtils; 30 31 import java.util.List; 32 33 /** 34 * Action to open the {@link com.android.settings.fuelgauge.RestrictedAppDetails} 35 */ 36 public class OpenRestrictAppFragmentAction extends BatteryTipAction { 37 private final RestrictAppTip mRestrictAppTip; 38 private final InstrumentedPreferenceFragment mFragment; 39 @VisibleForTesting 40 BatteryDatabaseManager mBatteryDatabaseManager; 41 OpenRestrictAppFragmentAction(InstrumentedPreferenceFragment fragment, RestrictAppTip tip)42 public OpenRestrictAppFragmentAction(InstrumentedPreferenceFragment fragment, 43 RestrictAppTip tip) { 44 super(fragment.getContext()); 45 mFragment = fragment; 46 mRestrictAppTip = tip; 47 mBatteryDatabaseManager = BatteryDatabaseManager.getInstance(mContext); 48 } 49 50 /** 51 * Handle the action when user clicks positive button 52 */ 53 @Override handlePositiveAction(int metricsKey)54 public void handlePositiveAction(int metricsKey) { 55 mMetricsFeatureProvider.action(mContext, 56 SettingsEnums.ACTION_TIP_OPEN_APP_RESTRICTION_PAGE, metricsKey); 57 final List<AppInfo> mAppInfos = mRestrictAppTip.getRestrictAppList(); 58 RestrictedAppDetails.startRestrictedAppDetails(mFragment, mAppInfos); 59 60 // Mark all the anomalies as handled, so it won't show up again. 61 ThreadUtils.postOnBackgroundThread(() -> mBatteryDatabaseManager.updateAnomalies(mAppInfos, 62 AnomalyDatabaseHelper.State.HANDLED)); 63 } 64 } 65