1 /* 2 * Copyright (C) 2017 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.system; 18 19 import android.car.drivingstate.CarUxRestrictions; 20 import android.content.Context; 21 import android.os.Build; 22 23 import androidx.annotation.VisibleForTesting; 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.Logger; 29 import com.android.car.settings.common.PreferenceController; 30 import com.android.settingslib.DeviceInfoUtils; 31 32 import java.util.concurrent.ExecutionException; 33 import java.util.concurrent.FutureTask; 34 35 /** Updates the hardware info entry summary with the device model. */ 36 public class HardwareInfoPreferenceController extends PreferenceController<Preference> { 37 38 private static final Logger LOG = new Logger(HardwareInfoPreferenceController.class); 39 HardwareInfoPreferenceController(Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions uxRestrictions)40 public HardwareInfoPreferenceController(Context context, String preferenceKey, 41 FragmentController fragmentController, CarUxRestrictions uxRestrictions) { 42 super(context, preferenceKey, fragmentController, uxRestrictions); 43 } 44 45 @Override getPreferenceType()46 protected Class<Preference> getPreferenceType() { 47 return Preference.class; 48 } 49 50 @Override updateState(Preference preference)51 protected void updateState(Preference preference) { 52 preference.setSummary( 53 getContext().getString(R.string.hardware_info_summary, getDeviceModel())); 54 } 55 getDeviceModel()56 private String getDeviceModel() { 57 FutureTask<String> msvSuffixTask = createMsvSuffixTask(); 58 59 msvSuffixTask.run(); 60 try { 61 // Wait for msv suffix value. 62 String msvSuffix = msvSuffixTask.get(); 63 return Build.MODEL + msvSuffix; 64 } catch (ExecutionException e) { 65 LOG.e("Execution error, so we only show model name"); 66 } catch (InterruptedException e) { 67 LOG.e("Interruption error, so we only show model name"); 68 } 69 // If we can't get an msv suffix value successfully, 70 // it's better to return model name. 71 return Build.MODEL; 72 } 73 74 @VisibleForTesting createMsvSuffixTask()75 FutureTask<String> createMsvSuffixTask() { 76 return new FutureTask<>(() -> DeviceInfoUtils.getMsvSuffix()); 77 } 78 } 79