Add getIMEI
Add adb command to get device IMEI
Test: adb shell cmd phone get-IMEI
Bug: 216150640
Change-Id: If872ff8556f844178db7cd0f6124a3aab493ab3a
diff --git a/src/com/android/phone/TelephonyShellCommand.java b/src/com/android/phone/TelephonyShellCommand.java
index 3cff658..b158588 100644
--- a/src/com/android/phone/TelephonyShellCommand.java
+++ b/src/com/android/phone/TelephonyShellCommand.java
@@ -172,6 +172,7 @@
"set-allowed-network-types-for-users";
// Check if telephony new data stack is enabled.
private static final String GET_DATA_MODE = "get-data-mode";
+ private static final String GET_IMEI = "get-imei";
// Take advantage of existing methods that already contain permissions checks when possible.
private final ITelephony mInterface;
@@ -328,6 +329,8 @@
return handleAllowedNetworkTypesCommand(cmd);
case GET_DATA_MODE:
return handleGetDataMode();
+ case GET_IMEI:
+ return handleGetImei();
case RADIO_SUBCOMMAND:
return handleRadioCommand();
default: {
@@ -382,6 +385,7 @@
onHelpDisableOrEnablePhysicalSubscription();
onHelpAllowedNetworkTypes();
onHelpRadio();
+ onHelpImei();
}
private void onHelpD2D() {
@@ -685,6 +689,15 @@
pw.println(" the result would be 'unknown'.");
}
+ private void onHelpImei() {
+ PrintWriter pw = getOutPrintWriter();
+ pw.println("IMEI Commands:");
+ pw.println(" get-imei [-s SLOT_ID]");
+ pw.println(" Gets the device IMEI. Options are:");
+ pw.println(" -s: the slot ID to get the IMEI. If no option");
+ pw.println(" is specified, it will choose the default voice SIM slot.");
+ }
+
private int handleImsCommand() {
String arg = getNextArg();
if (arg == null) {
@@ -1919,6 +1932,37 @@
return result ? 0 : -1;
}
+ private int handleGetImei() {
+ // Verify that the user is allowed to run the command. Only allowed in rooted device in a
+ // non user build.
+ if (Binder.getCallingUid() != Process.ROOT_UID || TelephonyUtils.IS_USER) {
+ getErrPrintWriter().println("Device IMEI: Permission denied.");
+ return -1;
+ }
+
+ final long identity = Binder.clearCallingIdentity();
+
+ String imei = null;
+ String arg = getNextArg();
+ if (arg != null) {
+ try {
+ int specifiedSlotIndex = Integer.parseInt(arg);
+ imei = TelephonyManager.from(mContext).getImei(specifiedSlotIndex);
+ } catch (NumberFormatException exception) {
+ PrintWriter errPw = getErrPrintWriter();
+ errPw.println("-s requires an integer as slot index.");
+ return -1;
+ }
+
+ } else {
+ imei = TelephonyManager.from(mContext).getImei();
+ }
+ getOutPrintWriter().println("Device IMEI: " + imei);
+
+ Binder.restoreCallingIdentity(identity);
+ return 0;
+ }
+
private int handleUnattendedReboot() {
// Verify that the user is allowed to run the command. Only allowed in rooted device in a
// non user build.