1 /* 2 * Copyright (C) 2009 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.mms; 18 19 import android.app.Activity; 20 import android.app.AlertDialog; 21 import android.content.Context; 22 import android.content.DialogInterface; 23 import android.content.DialogInterface.OnClickListener; 24 import android.util.Log; 25 26 import com.android.mms.data.Contact; 27 import com.android.mms.data.Conversation; 28 import com.android.mms.data.RecipientIdCache; 29 30 public class LogTag { 31 public static final String TAG = "Mms"; 32 33 public static final String TRANSACTION = TAG; 34 public static final String APP = TAG; 35 public static final String THREAD_CACHE = TAG; 36 public static final String THUMBNAIL_CACHE = TAG; 37 public static final String PDU_CACHE = TAG; 38 public static final String WIDGET = TAG; 39 public static final String CONTACT = TAG; 40 41 /** 42 * Log tag for enabling/disabling StrictMode violation log. 43 * To enable: adb shell setprop log.tag.Mms:strictmode DEBUG 44 */ 45 public static final String STRICT_MODE_TAG = TAG; 46 public static final boolean VERBOSE = false; 47 public static final boolean SEVERE_WARNING = true; // Leave this true 48 private static final boolean SHOW_SEVERE_WARNING_DIALOG = false; // Set to false before ship 49 public static final boolean DEBUG_SEND = false; // Set to false before ship 50 public static final boolean DEBUG_DUMP = false; // Set to false before ship 51 public static final boolean ALLOW_DUMP_IN_LOGS = false; // Set to false before ship 52 prettyArray(String[] array)53 private static String prettyArray(String[] array) { 54 if (array.length == 0) { 55 return "[]"; 56 } 57 58 StringBuilder sb = new StringBuilder("["); 59 int len = array.length-1; 60 for (int i = 0; i < len; i++) { 61 sb.append(array[i]); 62 sb.append(", "); 63 } 64 sb.append(array[len]); 65 sb.append("]"); 66 67 return sb.toString(); 68 } 69 logFormat(String format, Object... args)70 private static String logFormat(String format, Object... args) { 71 for (int i = 0; i < args.length; i++) { 72 if (args[i] instanceof String[]) { 73 args[i] = prettyArray((String[])args[i]); 74 } 75 } 76 String s = String.format(format, args); 77 s = "[" + Thread.currentThread().getId() + "] " + s; 78 return s; 79 } 80 debug(String format, Object... args)81 public static void debug(String format, Object... args) { 82 Log.d(TAG, logFormat(format, args)); 83 } 84 warn(String format, Object... args)85 public static void warn(String format, Object... args) { 86 Log.w(TAG, logFormat(format, args)); 87 } 88 error(String format, Object... args)89 public static void error(String format, Object... args) { 90 Log.e(TAG, logFormat(format, args)); 91 } 92 dumpInternalTables(final Context context)93 public static void dumpInternalTables(final Context context) { 94 if (!ALLOW_DUMP_IN_LOGS) { 95 return; 96 } 97 new Thread(new Runnable() { 98 public void run() { 99 RecipientIdCache.canonicalTableDump(); 100 RecipientIdCache.dump(); 101 Conversation.dumpThreadsTable(context); 102 Conversation.dump(); 103 Conversation.dumpSmsTable(context); 104 Contact.dump(); 105 } 106 }).start(); 107 } 108 warnPossibleRecipientMismatch(final String msg, final Activity activity)109 public static void warnPossibleRecipientMismatch(final String msg, final Activity activity) { 110 Log.e(TAG, "WARNING!!!! " + msg, new RuntimeException()); 111 112 if (SHOW_SEVERE_WARNING_DIALOG) { 113 dumpInternalTables(activity); 114 activity.runOnUiThread(new Runnable() { 115 public void run() { 116 new AlertDialog.Builder(activity) 117 .setIconAttribute(android.R.attr.alertDialogIcon) 118 .setTitle(R.string.error_state) 119 .setMessage(msg + "\n\n" + activity.getString(R.string.error_state_text)) 120 .setPositiveButton(R.string.yes, new OnClickListener() { 121 public void onClick(DialogInterface dialog, int which) { 122 dialog.dismiss(); 123 } 124 }) 125 .show(); 126 } 127 }); 128 } 129 } 130 131 } 132