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