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