Home | History | Annotate | Download | only in mms
      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 public class LogTag {
     27     public static final String TAG = "Mms";
     28 
     29     public static final String TRANSACTION = "Mms:transaction";
     30     public static final String APP = "Mms:app";
     31     public static final String THREAD_CACHE = "Mms:threadcache";
     32     public static final boolean VERBOSE = false;
     33     public static final boolean SEVERE_WARNING = true;                  // Leave this true
     34     private static final boolean SHOW_SEVERE_WARNING_DIALOG = false;    // Set to false before ship
     35 
     36     private static String prettyArray(String[] array) {
     37         if (array.length == 0) {
     38             return "[]";
     39         }
     40 
     41         StringBuilder sb = new StringBuilder("[");
     42         int len = array.length-1;
     43         for (int i = 0; i < len; i++) {
     44             sb.append(array[i]);
     45             sb.append(", ");
     46         }
     47         sb.append(array[len]);
     48         sb.append("]");
     49 
     50         return sb.toString();
     51     }
     52 
     53     private static String logFormat(String format, Object... args) {
     54         for (int i = 0; i < args.length; i++) {
     55             if (args[i] instanceof String[]) {
     56                 args[i] = prettyArray((String[])args[i]);
     57             }
     58         }
     59         String s = String.format(format, args);
     60         s = "[" + Thread.currentThread().getId() + "] " + s;
     61         return s;
     62     }
     63 
     64     public static void debug(String format, Object... args) {
     65         Log.d(TAG, logFormat(format, args));
     66     }
     67 
     68     public static void warn(String format, Object... args) {
     69         Log.w(TAG, logFormat(format, args));
     70     }
     71 
     72     public static void error(String format, Object... args) {
     73         Log.e(TAG, logFormat(format, args));
     74     }
     75 
     76     public static void warnPossibleRecipientMismatch(final String msg, final Activity activity) {
     77         Log.e(TAG, "WARNING!!!! " + msg);
     78 
     79         if (SHOW_SEVERE_WARNING_DIALOG) {
     80             activity.runOnUiThread(new Runnable() {
     81                 public void run() {
     82                     new AlertDialog.Builder(activity)
     83                         .setIcon(android.R.drawable.ic_dialog_alert)
     84                         .setTitle(R.string.error_state)
     85                         .setMessage(msg + "\n\n" + activity.getString(R.string.error_state_text))
     86                         .setPositiveButton(R.string.yes, new OnClickListener() {
     87                             public void onClick(DialogInterface dialog, int which) {
     88                                 dialog.dismiss();
     89                             }
     90                         })
     91                         .show();
     92                 }
     93             });
     94         }
     95     }
     96 
     97 }
     98