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.preference.Preference; 24 25 import com.android.car.settings.R; 26 import com.android.car.settings.common.FragmentController; 27 import com.android.car.settings.common.Logger; 28 import com.android.car.settings.common.PreferenceController; 29 import com.android.settingslib.DeviceInfoUtils; 30 31 import java.util.concurrent.ExecutionException; 32 import java.util.concurrent.FutureTask; 33 34 /** Updates the hardware info entry summary with the device model. */ 35 public class HardwareInfoPreferenceController extends PreferenceController<Preference> { 36 37 private static final Logger LOG = new Logger(HardwareInfoPreferenceController.class); 38 HardwareInfoPreferenceController(Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions uxRestrictions)39 public HardwareInfoPreferenceController(Context context, String preferenceKey, 40 FragmentController fragmentController, 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 updateState(Preference preference)50 protected void updateState(Preference preference) { 51 preference.setSummary( 52 getContext().getString(R.string.hardware_info_summary, getDeviceModel())); 53 } 54 getDeviceModel()55 private static String getDeviceModel() { 56 FutureTask<String> msvSuffixTask = new FutureTask<>(() -> DeviceInfoUtils.getMsvSuffix()); 57 58 msvSuffixTask.run(); 59 try { 60 // Wait for msv suffix value. 61 String msvSuffix = msvSuffixTask.get(); 62 return Build.MODEL + msvSuffix; 63 } catch (ExecutionException e) { 64 LOG.e("Execution error, so we only show model name"); 65 } catch (InterruptedException e) { 66 LOG.e("Interruption error, so we only show model name"); 67 } 68 // If we can't get an msv suffix value successfully, 69 // it's better to return model name. 70 return Build.MODEL; 71 } 72 } 73