PageRenderTime 60ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/telephony/java/android/telephony/SubscriptionInfo.java

http://github.com/CyanogenMod/android_frameworks_base
Java | 376 lines | 185 code | 48 blank | 143 comment | 5 complexity | 508dc06451d08fc7f3cc59956febd653 MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception, CC0-1.0, BitTorrent-1.0, BSD-3-Clause
  1. /*
  2. * Copyright (C) 2014 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. package android.telephony;
  17. import android.content.Context;
  18. import android.graphics.Bitmap;
  19. import android.graphics.Canvas;
  20. import android.graphics.Color;
  21. import android.graphics.Paint;
  22. import android.graphics.PorterDuff;
  23. import android.graphics.PorterDuffColorFilter;
  24. import android.graphics.Rect;
  25. import android.graphics.Typeface;
  26. import android.os.Build;
  27. import android.os.Parcel;
  28. import android.os.Parcelable;
  29. import android.util.DisplayMetrics;
  30. /**
  31. * A Parcelable class for Subscription Information.
  32. */
  33. public class SubscriptionInfo implements Parcelable {
  34. /**
  35. * Size of text to render on the icon.
  36. */
  37. private static final int TEXT_SIZE = 16;
  38. /**
  39. * Subscription Identifier, this is a device unique number
  40. * and not an index into an array
  41. */
  42. private int mId;
  43. /**
  44. * The GID for a SIM that maybe associated with this subscription, empty if unknown
  45. */
  46. private String mIccId;
  47. /**
  48. * The index of the slot that currently contains the subscription
  49. * and not necessarily unique and maybe INVALID_SLOT_ID if unknown
  50. */
  51. private int mSimSlotIndex;
  52. /**
  53. * The name displayed to the user that identifies this subscription
  54. */
  55. private CharSequence mDisplayName;
  56. /**
  57. * String that identifies SPN/PLMN
  58. * TODO : Add a new field that identifies only SPN for a sim
  59. */
  60. private CharSequence mCarrierName;
  61. /**
  62. * The source of the name, NAME_SOURCE_UNDEFINED, NAME_SOURCE_DEFAULT_SOURCE,
  63. * NAME_SOURCE_SIM_SOURCE or NAME_SOURCE_USER_INPUT.
  64. */
  65. private int mNameSource;
  66. /**
  67. * The color to be used for tinting the icon when displaying to the user
  68. */
  69. private int mIconTint;
  70. /**
  71. * A number presented to the user identify this subscription
  72. */
  73. private String mNumber;
  74. /**
  75. * Data roaming state, DATA_RAOMING_ENABLE, DATA_RAOMING_DISABLE
  76. */
  77. private int mDataRoaming;
  78. /**
  79. * SIM Icon bitmap
  80. */
  81. private Bitmap mIconBitmap;
  82. /**
  83. * Mobile Country Code
  84. */
  85. private int mMcc;
  86. /**
  87. * Mobile Network Code
  88. */
  89. private int mMnc;
  90. /**
  91. * ISO Country code for the subscription's provider
  92. */
  93. private String mCountryIso;
  94. /**
  95. * @hide
  96. */
  97. public int mUserNwMode;
  98. /**
  99. * @hide
  100. */
  101. public SubscriptionInfo(int id, String iccId, int simSlotIndex, CharSequence displayName,
  102. CharSequence carrierName, int nameSource, int iconTint, String number, int roaming,
  103. Bitmap icon, int mcc, int mnc, String countryIso, int userNwMode) {
  104. this.mId = id;
  105. this.mIccId = iccId;
  106. this.mSimSlotIndex = simSlotIndex;
  107. this.mDisplayName = displayName;
  108. this.mCarrierName = carrierName;
  109. this.mNameSource = nameSource;
  110. this.mIconTint = iconTint;
  111. this.mNumber = number;
  112. this.mDataRoaming = roaming;
  113. this.mIconBitmap = icon;
  114. this.mMcc = mcc;
  115. this.mMnc = mnc;
  116. this.mCountryIso = countryIso;
  117. this.mUserNwMode = userNwMode;
  118. }
  119. /**
  120. * @return the subscription ID.
  121. */
  122. public int getSubscriptionId() {
  123. return this.mId;
  124. }
  125. /**
  126. * @return the ICC ID.
  127. */
  128. public String getIccId() {
  129. return this.mIccId;
  130. }
  131. /**
  132. * @return the slot index of this Subscription's SIM card.
  133. */
  134. public int getSimSlotIndex() {
  135. return this.mSimSlotIndex;
  136. }
  137. /**
  138. * @return the name displayed to the user that identifies this subscription
  139. */
  140. public CharSequence getDisplayName() {
  141. return this.mDisplayName;
  142. }
  143. /**
  144. * Sets the name displayed to the user that identifies this subscription
  145. * @hide
  146. */
  147. public void setDisplayName(CharSequence name) {
  148. this.mDisplayName = name;
  149. }
  150. /**
  151. * @return the name displayed to the user that identifies Subscription provider name
  152. */
  153. public CharSequence getCarrierName() {
  154. return this.mCarrierName;
  155. }
  156. /**
  157. * Sets the name displayed to the user that identifies Subscription provider name
  158. * @hide
  159. */
  160. public void setCarrierName(CharSequence name) {
  161. this.mCarrierName = name;
  162. }
  163. /**
  164. * @return the source of the name, eg NAME_SOURCE_UNDEFINED, NAME_SOURCE_DEFAULT_SOURCE,
  165. * NAME_SOURCE_SIM_SOURCE or NAME_SOURCE_USER_INPUT.
  166. * @hide
  167. */
  168. public int getNameSource() {
  169. return this.mNameSource;
  170. }
  171. /**
  172. * Creates and returns an icon {@code Bitmap} to represent this {@code SubscriptionInfo} in a user
  173. * interface.
  174. *
  175. * @param context A {@code Context} to get the {@code DisplayMetrics}s from.
  176. *
  177. * @return A bitmap icon for this {@code SubscriptionInfo}.
  178. */
  179. public Bitmap createIconBitmap(Context context) {
  180. int width = mIconBitmap.getWidth();
  181. int height = mIconBitmap.getHeight();
  182. DisplayMetrics metrics = context.getResources().getDisplayMetrics();
  183. // Create a new bitmap of the same size because it will be modified.
  184. Bitmap workingBitmap = Bitmap.createBitmap(metrics, width, height, mIconBitmap.getConfig());
  185. Canvas canvas = new Canvas(workingBitmap);
  186. Paint paint = new Paint();
  187. // Tint the icon with the color.
  188. paint.setColorFilter(new PorterDuffColorFilter(mIconTint, PorterDuff.Mode.SRC_ATOP));
  189. canvas.drawBitmap(mIconBitmap, 0, 0, paint);
  190. paint.setColorFilter(null);
  191. // Write the sim slot index.
  192. paint.setAntiAlias(true);
  193. paint.setTypeface(Typeface.create("sans-serif", Typeface.NORMAL));
  194. paint.setColor(Color.WHITE);
  195. // Set text size scaled by density
  196. paint.setTextSize(TEXT_SIZE * metrics.density);
  197. // Convert sim slot index to localized string
  198. final String index = String.format("%d", mSimSlotIndex + 1);
  199. final Rect textBound = new Rect();
  200. paint.getTextBounds(index, 0, 1, textBound);
  201. final float xOffset = (width / 2.f) - textBound.centerX();
  202. final float yOffset = (height / 2.f) - textBound.centerY();
  203. canvas.drawText(index, xOffset, yOffset, paint);
  204. return workingBitmap;
  205. }
  206. /**
  207. * A highlight color to use in displaying information about this {@code PhoneAccount}.
  208. *
  209. * @return A hexadecimal color value.
  210. */
  211. public int getIconTint() {
  212. return mIconTint;
  213. }
  214. /**
  215. * Sets the color displayed to the user that identifies this subscription
  216. * @hide
  217. */
  218. public void setIconTint(int iconTint) {
  219. this.mIconTint = iconTint;
  220. }
  221. /**
  222. * @return the number of this subscription.
  223. */
  224. public String getNumber() {
  225. return mNumber;
  226. }
  227. /**
  228. * @return the data roaming state for this subscription, either
  229. * {@link SubscriptionManager#DATA_ROAMING_ENABLE} or {@link SubscriptionManager#DATA_ROAMING_DISABLE}.
  230. */
  231. public int getDataRoaming() {
  232. return this.mDataRoaming;
  233. }
  234. /**
  235. * @return the MCC.
  236. */
  237. public int getMcc() {
  238. return this.mMcc;
  239. }
  240. /**
  241. * @return the MNC.
  242. */
  243. public int getMnc() {
  244. return this.mMnc;
  245. }
  246. /**
  247. * @return the ISO country code
  248. */
  249. public String getCountryIso() {
  250. return this.mCountryIso;
  251. }
  252. /**
  253. * Returns the user set network mode.
  254. * @hide
  255. */
  256. public int getUserNwMode() {
  257. return this.mUserNwMode;
  258. }
  259. public static final Parcelable.Creator<SubscriptionInfo> CREATOR = new Parcelable.Creator<SubscriptionInfo>() {
  260. @Override
  261. public SubscriptionInfo createFromParcel(Parcel source) {
  262. int id = source.readInt();
  263. String iccId = source.readString();
  264. int simSlotIndex = source.readInt();
  265. CharSequence displayName = source.readCharSequence();
  266. CharSequence carrierName = source.readCharSequence();
  267. int nameSource = source.readInt();
  268. int iconTint = source.readInt();
  269. String number = source.readString();
  270. int dataRoaming = source.readInt();
  271. int mcc = source.readInt();
  272. int mnc = source.readInt();
  273. int userNwMode = source.readInt();
  274. String countryIso = source.readString();
  275. Bitmap iconBitmap = Bitmap.CREATOR.createFromParcel(source);
  276. return new SubscriptionInfo(id, iccId, simSlotIndex, displayName, carrierName,
  277. nameSource, iconTint, number, dataRoaming, iconBitmap, mcc, mnc, countryIso, userNwMode);
  278. }
  279. @Override
  280. public SubscriptionInfo[] newArray(int size) {
  281. return new SubscriptionInfo[size];
  282. }
  283. };
  284. @Override
  285. public void writeToParcel(Parcel dest, int flags) {
  286. dest.writeInt(mId);
  287. dest.writeString(mIccId);
  288. dest.writeInt(mSimSlotIndex);
  289. dest.writeCharSequence(mDisplayName);
  290. dest.writeCharSequence(mCarrierName);
  291. dest.writeInt(mNameSource);
  292. dest.writeInt(mIconTint);
  293. dest.writeString(mNumber);
  294. dest.writeInt(mDataRoaming);
  295. dest.writeInt(mMcc);
  296. dest.writeInt(mMnc);
  297. dest.writeInt(mUserNwMode);
  298. dest.writeString(mCountryIso);
  299. mIconBitmap.writeToParcel(dest, flags);
  300. }
  301. @Override
  302. public int describeContents() {
  303. return 0;
  304. }
  305. /**
  306. * @hide
  307. */
  308. public static String givePrintableIccid(String iccId) {
  309. String iccIdToPrint = null;
  310. if (iccId != null) {
  311. if (iccId.length() > 9 && !Build.IS_DEBUGGABLE) {
  312. iccIdToPrint = iccId.substring(0, 9) + Rlog.pii(false, iccId.substring(9));
  313. } else {
  314. iccIdToPrint = iccId;
  315. }
  316. }
  317. return iccIdToPrint;
  318. }
  319. @Override
  320. public String toString() {
  321. String iccIdToPrint = givePrintableIccid(mIccId);
  322. return "{id=" + mId + ", iccId=" + iccIdToPrint + " simSlotIndex=" + mSimSlotIndex
  323. + " displayName=" + mDisplayName + " carrierName=" + mCarrierName
  324. + " nameSource=" + mNameSource + " iconTint=" + mIconTint
  325. + " dataRoaming=" + mDataRoaming + " iconBitmap=" + mIconBitmap + " mcc " + mMcc
  326. + " mnc " + mMnc + " userNwMode=" + mUserNwMode + "}";
  327. }
  328. }