1 /* 2 * Copyright (C) 2021 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.car.settings.applications; 18 19 import static com.android.car.settings.applications.ApplicationsUtils.isHibernationEnabled; 20 21 import android.car.drivingstate.CarUxRestrictions; 22 import android.content.Context; 23 24 import androidx.preference.Preference; 25 26 import com.android.car.settings.R; 27 import com.android.car.settings.common.FragmentController; 28 import com.android.car.settings.common.PreferenceController; 29 import com.android.settingslib.utils.StringUtil; 30 31 /** 32 * A preference controller handling the logic for updating summary of hibernated apps. 33 */ 34 public final class HibernatedAppsPreferenceController extends PreferenceController<Preference> 35 implements HibernatedAppsItemManager.HibernatedAppsCountListener { 36 private static final String TAG = "HibernatedAppsPrefController"; 37 HibernatedAppsPreferenceController(Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions uxRestrictions)38 public HibernatedAppsPreferenceController(Context context, String preferenceKey, 39 FragmentController fragmentController, 40 CarUxRestrictions uxRestrictions) { 41 super(context, preferenceKey, fragmentController, uxRestrictions); 42 } 43 44 @Override getPreferenceType()45 protected Class<Preference> getPreferenceType() { 46 return Preference.class; 47 } 48 49 @Override getDefaultAvailabilityStatus()50 public int getDefaultAvailabilityStatus() { 51 return isHibernationEnabled() ? AVAILABLE : CONDITIONALLY_UNAVAILABLE; 52 } 53 54 @Override onHibernatedAppsCountLoaded(int hibernatedAppsCount)55 public void onHibernatedAppsCountLoaded(int hibernatedAppsCount) { 56 getPreference().setSummary(StringUtil.getIcuPluralsString(getContext(), hibernatedAppsCount, 57 R.string.unused_apps_summary)); 58 refreshUi(); 59 } 60 } 61