1 /* 2 * Copyright (C) 2024 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.appinfo; 18 19 import android.car.drivingstate.CarUxRestrictions; 20 import android.content.Context; 21 import android.content.pm.ApplicationInfo; 22 23 import com.android.car.settings.common.FragmentController; 24 import com.android.car.settings.common.Logger; 25 import com.android.car.settings.common.PreferenceController; 26 import com.android.car.ui.preference.CarUiPreference; 27 28 /** 29 * A PreferenceController handling the logic for setting an app's aspect ratio 30 */ 31 public final class AppAspectRatioPreferenceController extends 32 PreferenceController<CarUiPreference> { 33 private static final Logger LOG = new Logger(AppAspectRatioPreferenceController.class); 34 private static final String PACKAGE_UI_SCHEME = "package:"; 35 private ApplicationInfo mApplicationInfo; 36 private AspectRatioManager mAspectRatioManager; 37 private String mPackageName; 38 AppAspectRatioPreferenceController(Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions uxRestrictions)39 public AppAspectRatioPreferenceController(Context context, String preferenceKey, 40 FragmentController fragmentController, 41 CarUxRestrictions uxRestrictions) { 42 super(context, preferenceKey, fragmentController, uxRestrictions); 43 mAspectRatioManager = new AspectRatioManager(context); 44 } 45 46 @Override getPreferenceType()47 protected Class<CarUiPreference> getPreferenceType() { 48 return CarUiPreference.class; 49 } 50 51 @Override getDefaultAvailabilityStatus()52 public int getDefaultAvailabilityStatus() { 53 return mAspectRatioManager.shouldShowAspectRatioSettingsForApp(mApplicationInfo) 54 ? AVAILABLE : UNSUPPORTED_ON_DEVICE; 55 } 56 57 /** 58 * Set the ApplicationInfo associated with this setting. 59 * 60 * @param applicationInfo The applicationInfo of the app to change aspect ratio. 61 */ setApplicationInfo(ApplicationInfo applicationInfo)62 public AppAspectRatioPreferenceController setApplicationInfo(ApplicationInfo applicationInfo) { 63 mApplicationInfo = applicationInfo; 64 return this; 65 } 66 67 /** 68 * Set the packageName, which is used to perform actions on a particular package. 69 */ setPackageName(String packageName)70 public AppAspectRatioPreferenceController setPackageName(String packageName) { 71 mPackageName = packageName; 72 return this; 73 } 74 75 @Override handlePreferenceClicked(CarUiPreference preference)76 protected boolean handlePreferenceClicked(CarUiPreference preference) { 77 getFragmentController().launchFragment( 78 AppAspectRatioFragment.getInstance(mPackageName)); 79 return true; 80 } 81 } 82