From c7cd74f811fc249b1c1ef0f95740134e2da54a41 Mon Sep 17 00:00:00 2001 From: Daniel Bateman Date: Wed, 15 Aug 2012 01:05:14 -0500 Subject: aries-common: Add sanity checking Purpose: Verify the integrity of select things including the IMEI. The IMEI specifically, if invalid, could cause emergency calling issues (i.e. inability to call at all). Warn the user if any issues are detected. Currently only the IMEI is checked against the generic IMEI (004999010640000). Change-Id: I8fb76b7535cc7110142b72892cf9d4fc1cbc25e7 --- AriesParts/AndroidManifest.xml | 4 ++ AriesParts/res/values/strings.xml | 9 +++++ .../com/cyanogenmod/settings/device/Sanity.java | 38 +++++++++++++++++++ .../com/cyanogenmod/settings/device/Startup.java | 1 + .../cyanogenmod/settings/device/WarnActivity.java | 43 ++++++++++++++++++++++ 5 files changed, 95 insertions(+) create mode 100644 AriesParts/src/com/cyanogenmod/settings/device/Sanity.java create mode 100644 AriesParts/src/com/cyanogenmod/settings/device/WarnActivity.java diff --git a/AriesParts/AndroidManifest.xml b/AriesParts/AndroidManifest.xml index 7debe38..137d83d 100644 --- a/AriesParts/AndroidManifest.xml +++ b/AriesParts/AndroidManifest.xml @@ -3,6 +3,7 @@ package="com.cyanogenmod.settings.device" android:sharedUserId="android.uid.system"> + + diff --git a/AriesParts/res/values/strings.xml b/AriesParts/res/values/strings.xml index 80679a0..ef450f3 100644 --- a/AriesParts/res/values/strings.xml +++ b/AriesParts/res/values/strings.xml @@ -50,4 +50,13 @@ Desk dock audio enabled Desk dock audio disabled + + Warning + + + Warning! + A problem was detected with your device. Your device IMEI number is invalid. An invalid IMEI number could cause network issues including the inability to call emergency numbers. + OK + diff --git a/AriesParts/src/com/cyanogenmod/settings/device/Sanity.java b/AriesParts/src/com/cyanogenmod/settings/device/Sanity.java new file mode 100644 index 0000000..981b884 --- /dev/null +++ b/AriesParts/src/com/cyanogenmod/settings/device/Sanity.java @@ -0,0 +1,38 @@ +package com.cyanogenmod.settings.device; + +import android.content.Context; +import android.content.Intent; +import android.telephony.TelephonyManager; +import android.util.Log; + +public class Sanity { + private static final String TAG = "AriesParts"; + private static final String BAD_IMEI[] = { + "004999010640000" + }; + + public static void check(Context context) { + TelephonyManager tm = (TelephonyManager) context.getSystemService( + Context.TELEPHONY_SERVICE); + String id = tm.getDeviceId(); + if (tm.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM && !ensureIMEISanity(id)) { + Log.e(TAG, "Invalid IMEI!"); + Intent intent = new Intent(context, WarnActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + intent.putExtra(WarnActivity.KEY_REASON, WarnActivity.REASON_INVALID_IMEI); + context.startActivity(intent); + return; + } + Log.d(TAG, "Device is sane."); + } + + public static boolean ensureIMEISanity(String id) { + Log.d(TAG, "Current IMEI: " + id); + for (int j = 0; j < BAD_IMEI.length; j++) { + if (BAD_IMEI[j].equals(id)) { + return false; + } + } + return true; + } +} diff --git a/AriesParts/src/com/cyanogenmod/settings/device/Startup.java b/AriesParts/src/com/cyanogenmod/settings/device/Startup.java index 901f47e..924a95d 100644 --- a/AriesParts/src/com/cyanogenmod/settings/device/Startup.java +++ b/AriesParts/src/com/cyanogenmod/settings/device/Startup.java @@ -14,6 +14,7 @@ public class Startup extends BroadcastReceiver { Hspa.restore(context); VolumeBoostPreference.restore(context); DockAudio.restore(context); + Sanity.check(context); } } diff --git a/AriesParts/src/com/cyanogenmod/settings/device/WarnActivity.java b/AriesParts/src/com/cyanogenmod/settings/device/WarnActivity.java new file mode 100644 index 0000000..34488ee --- /dev/null +++ b/AriesParts/src/com/cyanogenmod/settings/device/WarnActivity.java @@ -0,0 +1,43 @@ +package com.cyanogenmod.settings.device; + +import android.os.Bundle; +import android.content.Intent; +import android.app.Dialog; +import android.app.Activity; +import android.app.AlertDialog; +import android.view.Window; +import android.content.DialogInterface; +import android.util.Log; + +public class WarnActivity extends Activity { + public static final String KEY_REASON = "sanity_reason"; + public static final String REASON_INVALID_IMEI = "invalid_imei"; + + @Override + public void onCreate(Bundle icicle) { + super.onCreate(icicle); + requestWindowFeature(Window.FEATURE_NO_TITLE); + + Bundle extras = getIntent().getExtras(); + String reason = extras.getString(KEY_REASON); + + if (REASON_INVALID_IMEI.equals(reason)) { + showInvalidImei(); + } + } + + private void showInvalidImei() { + new AlertDialog.Builder(this) + .setTitle(getString(R.string.imei_not_sane_title)) + .setMessage(getString(R.string.imei_not_sane_message)) + .setPositiveButton(getString(R.string.imei_not_sane_ok), + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.cancel(); + finish(); + } + }) + .setCancelable(false) + .create().show(); + } +} -- cgit v1.1