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.systemui.car.systembar; 18 19 import android.car.Car; 20 import android.car.VehicleAreaType; 21 import android.car.VehiclePropertyIds; 22 import android.car.hardware.CarPropertyValue; 23 import android.car.hardware.property.CarPropertyManager; 24 import android.content.Context; 25 import android.os.Build; 26 import android.text.TextUtils; 27 28 import androidx.annotation.ArrayRes; 29 30 import com.android.systemui.R; 31 32 import java.util.Set; 33 34 /** 35 * Contains utility functions for build info. 36 */ 37 // TODO(b/371116800): move this class to car-apps-common library 38 public class BuildInfoUtil { 39 BuildInfoUtil()40 private BuildInfoUtil() { 41 } 42 43 /** 44 * Returns true for builds that are for testing for developers. 45 */ isDevTesting(Context context)46 public static boolean isDevTesting(Context context) { 47 return (Build.IS_ENG || Build.IS_USERDEBUG) && isSupportedBenchOrEmulator(context); 48 } 49 50 /** 51 * Returns true for builds that are on benches or emulators. 52 */ isSupportedBenchOrEmulator(Context context)53 public static boolean isSupportedBenchOrEmulator(Context context) { 54 return isEmulator() || isSupportedDebugDevice(context) || isSupportedDebugDeviceExcludeCar( 55 context); 56 } 57 isEmulator()58 private static boolean isEmulator() { 59 return Build.IS_EMULATOR; 60 } 61 isSupportedDebugDevice(Context context)62 private static boolean isSupportedDebugDevice(Context context) { 63 return isDebugDeviceIncluded(context, R.array.config_debug_support_devices); 64 } 65 isDebugDeviceIncluded(Context context, @ArrayRes int resId)66 private static boolean isDebugDeviceIncluded(Context context, @ArrayRes int resId) { 67 Set<String> supportedDevices = Set.of(context.getResources().getStringArray(resId)); 68 return supportedDevices.contains(Build.DEVICE); 69 } 70 isSupportedDebugDeviceExcludeCar(Context context)71 private static boolean isSupportedDebugDeviceExcludeCar(Context context) { 72 return isDebugDeviceIncluded(context, R.array.config_debug_support_devices_exclude_car) 73 && !isRealCar(context); 74 } 75 76 /** 77 * Please make sure the VIN numbers on the benches are reset before using this function, 78 * follow the instructions in b/267517048. 79 */ isRealCar(Context context)80 private static boolean isRealCar(Context context) { 81 Car car = Car.createCar(context); 82 CarPropertyManager carPropertyManager = null; 83 if (car != null) { 84 carPropertyManager = (CarPropertyManager) car.getCarManager(Car.PROPERTY_SERVICE); 85 } 86 if (carPropertyManager != null) { 87 try { 88 CarPropertyValue carPropertyValue = carPropertyManager.getProperty( 89 VehiclePropertyIds.INFO_VIN, VehicleAreaType.VEHICLE_AREA_TYPE_GLOBAL); 90 if (carPropertyValue != null && carPropertyValue.getPropertyStatus() 91 == CarPropertyValue.STATUS_AVAILABLE) { 92 if (TextUtils.isDigitsOnly((CharSequence) carPropertyValue.getValue())) { 93 return Long.valueOf((String) carPropertyValue.getValue()) != 0; 94 } else { 95 return true; 96 } 97 } 98 } catch (Exception e) { 99 // For the situations where there are exceptions, the status of the device is 100 // uncertain, so it will be treated as a real car in order to avoid showing the 101 // debug only features. 102 return true; 103 } 104 } 105 // Normally a real car should always have the proper service setup. 106 return false; 107 } 108 } 109