1 /* 2 * Copyright (C) 2018 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.server.wifi.hotspot2; 18 19 import android.annotation.NonNull; 20 import android.content.Context; 21 import android.os.Build; 22 import android.os.SystemProperties; 23 import android.telephony.SubscriptionManager; 24 import android.telephony.TelephonyManager; 25 import android.text.TextUtils; 26 27 import com.android.internal.annotations.VisibleForTesting; 28 import com.android.internal.telephony.TelephonyProperties; 29 import com.android.server.wifi.WifiNative; 30 31 import java.util.Locale; 32 33 /** 34 * Provide APIs for retrieving system information, so that they can be mocked for unit tests. 35 */ 36 public class SystemInfo { 37 public static final String TAG = "SystemInfo"; 38 public static final String UNKNOWN_INFO = "Unknown"; 39 40 private final TelephonyManager mTelephonyManager; 41 private final WifiNative mWifiNative; 42 private static SystemInfo sSystemInfo = null; 43 44 @VisibleForTesting SystemInfo(Context context, WifiNative wifiNative)45 SystemInfo(Context context, WifiNative wifiNative) { 46 // TODO(b/132188983): inject this using WifiInjector 47 mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); 48 mWifiNative = wifiNative; 49 } 50 getInstance(@onNull Context context, @NonNull WifiNative wifiNative)51 public static SystemInfo getInstance(@NonNull Context context, @NonNull WifiNative wifiNative) { 52 if (sSystemInfo == null) { 53 sSystemInfo = new SystemInfo(context, wifiNative); 54 } 55 return sSystemInfo; 56 } 57 58 /** 59 * Get the system language. 60 * 61 * @return current language code 62 */ getLanguage()63 public String getLanguage() { 64 return Locale.getDefault().getLanguage(); 65 } 66 67 /** 68 * Get the device manufacturer info 69 * 70 * @return the device manufacturer info or {@link Build#UNKNOWN} if not set 71 */ getDeviceManufacturer()72 public String getDeviceManufacturer() { 73 return Build.MANUFACTURER; 74 } 75 76 /** 77 * Get the device model info. 78 * 79 * @return the device model info or {@link Build#UNKNOWN} if not set 80 */ getDeviceModel()81 public String getDeviceModel() { 82 return Build.MODEL; 83 } 84 85 /** 86 * Get the Wifi Mac address for primary interface. 87 * 88 * TODO(b/80092273): need to check if this privacy information is required for Passpoint R2. 89 * @param ifaceName Name of the interface. 90 * @return string containing the MAC address or null on a failed call 91 */ getMacAddress(@onNull String ifaceName)92 public String getMacAddress(@NonNull String ifaceName) { 93 return mWifiNative.getMacAddress(ifaceName); 94 } 95 96 /** 97 * Get the device ID. Either IMEI or MEID will be returned based on the installed SIM. 98 * {@link #UNKNOWN_INFO} will be returned if no SIM is installed. 99 * 100 * @return String representing device ID 101 */ getDeviceId()102 public String getDeviceId() { 103 TelephonyManager defaultDataTm = mTelephonyManager.createForSubscriptionId( 104 SubscriptionManager.getDefaultDataSubscriptionId()); 105 // IMEI will be provided for GSM SIM. 106 String imei = defaultDataTm.getImei(); 107 if (!TextUtils.isEmpty(imei)) { 108 return imei; 109 } 110 111 // MEID will be provided for CMDA SIM. 112 String meid = defaultDataTm.getMeid(); 113 if (!TextUtils.isEmpty(meid)) { 114 return meid; 115 } 116 return UNKNOWN_INFO; 117 } 118 119 /** 120 * Get the hardware version. 121 * 122 * TODO(b/80092273): need to check if this privacy information is required for Passpoint R2. 123 * @return the version that consists of hardware name and revision number. 124 */ getHwVersion()125 public String getHwVersion() { 126 return Build.HARDWARE + "." + SystemProperties.get("ro.revision", "0"); 127 } 128 129 /** 130 * Get the software version. 131 * 132 * @return the build release version. 133 */ getSoftwareVersion()134 public String getSoftwareVersion() { 135 return new StringBuffer("Android ").append(Build.VERSION.RELEASE).toString(); 136 } 137 138 /** 139 * Get the firmware version. 140 * 141 * @return the version that consists of build id and baseband version. 142 */ getFirmwareVersion()143 public String getFirmwareVersion() { 144 return new StringBuffer(Build.ID) 145 .append("/") 146 .append(SystemProperties.get(TelephonyProperties.PROPERTY_BASEBAND_VERSION, 147 UNKNOWN_INFO)).toString(); 148 } 149 } 150