1 /* 2 * Copyright (C) 2008 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.email.activity; 18 19 import com.android.email.Controller; 20 import com.android.email.Email; 21 import com.android.email.Preferences; 22 import com.android.email.R; 23 import com.android.exchange.Eas; 24 import com.android.exchange.utility.FileLogger; 25 26 import android.app.Activity; 27 import android.content.Context; 28 import android.os.Bundle; 29 import android.view.Menu; 30 import android.view.MenuItem; 31 import android.widget.CheckBox; 32 import android.widget.CompoundButton; 33 import android.widget.TextView; 34 import android.widget.CompoundButton.OnCheckedChangeListener; 35 36 public class Debug extends Activity implements OnCheckedChangeListener { 37 private TextView mVersionView; 38 private CheckBox mEnableDebugLoggingView; 39 private CheckBox mEnableSensitiveLoggingView; 40 private CheckBox mEnableExchangeLoggingView; 41 private CheckBox mEnableExchangeFileLoggingView; 42 43 private Preferences mPreferences; 44 45 @Override onCreate(Bundle savedInstanceState)46 public void onCreate(Bundle savedInstanceState) { 47 super.onCreate(savedInstanceState); 48 49 setContentView(R.layout.debug); 50 51 mPreferences = Preferences.getPreferences(this); 52 53 mVersionView = (TextView)findViewById(R.id.version); 54 mEnableDebugLoggingView = (CheckBox)findViewById(R.id.debug_logging); 55 mEnableSensitiveLoggingView = (CheckBox)findViewById(R.id.sensitive_logging); 56 57 mVersionView.setText(String.format(getString(R.string.debug_version_fmt).toString(), 58 getString(R.string.build_number))); 59 60 mEnableDebugLoggingView.setChecked(Email.DEBUG); 61 mEnableSensitiveLoggingView.setChecked(Email.DEBUG_SENSITIVE); 62 63 //EXCHANGE-REMOVE-SECTION-START 64 mEnableExchangeLoggingView = (CheckBox)findViewById(R.id.exchange_logging); 65 mEnableExchangeFileLoggingView = (CheckBox)findViewById(R.id.exchange_file_logging); 66 mEnableExchangeLoggingView.setChecked(Eas.PARSER_LOG); 67 mEnableExchangeFileLoggingView.setChecked(Eas.FILE_LOG); 68 //EXCHANGE-REMOVE-SECTION-END 69 70 // Note: To prevent recursion while presetting checkboxes, assign all listeners last 71 mEnableDebugLoggingView.setOnCheckedChangeListener(this); 72 mEnableSensitiveLoggingView.setOnCheckedChangeListener(this); 73 //EXCHANGE-REMOVE-SECTION-START 74 mEnableExchangeLoggingView.setOnCheckedChangeListener(this); 75 mEnableExchangeFileLoggingView.setOnCheckedChangeListener(this); 76 //EXCHANGE-REMOVE-SECTION-END 77 } 78 onCheckedChanged(CompoundButton buttonView, boolean isChecked)79 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 80 switch (buttonView.getId()) { 81 case R.id.debug_logging: 82 Email.DEBUG = isChecked; 83 mPreferences.setEnableDebugLogging(Email.DEBUG); 84 break; 85 case R.id.sensitive_logging: 86 Email.DEBUG_SENSITIVE = isChecked; 87 mPreferences.setEnableSensitiveLogging(Email.DEBUG_SENSITIVE); 88 break; 89 //EXCHANGE-REMOVE-SECTION-START 90 case R.id.exchange_logging: 91 mPreferences.setEnableExchangeLogging(isChecked); 92 break; 93 case R.id.exchange_file_logging: 94 mPreferences.setEnableExchangeFileLogging(isChecked); 95 if (!isChecked) { 96 FileLogger.close(); 97 } 98 break; 99 //EXCHANGE-REMOVE-SECTION-END 100 } 101 102 updateLoggingFlags(this); 103 } 104 105 @Override onOptionsItemSelected(MenuItem item)106 public boolean onOptionsItemSelected(MenuItem item) { 107 int id = item.getItemId(); 108 if (id == R.id.dump_settings) { 109 Preferences.getPreferences(this).dump(); 110 return true; 111 } 112 return super.onOptionsItemSelected(item); 113 } 114 115 @Override onCreateOptionsMenu(Menu menu)116 public boolean onCreateOptionsMenu(Menu menu) { 117 super.onCreateOptionsMenu(menu); 118 getMenuInflater().inflate(R.menu.debug_option, menu); 119 return true; 120 } 121 122 /** 123 * Load enabled debug flags from the preferences and upadte the EAS debug flag. 124 */ updateLoggingFlags(Context context)125 public static void updateLoggingFlags(Context context) { 126 //EXCHANGE-REMOVE-SECTION-START 127 Preferences prefs = Preferences.getPreferences(context); 128 int debugLogging = prefs.getEnableDebugLogging() ? Eas.DEBUG_BIT : 0; 129 int exchangeLogging = prefs.getEnableExchangeLogging() ? Eas.DEBUG_EXCHANGE_BIT : 0; 130 int fileLogging = prefs.getEnableExchangeFileLogging() ? Eas.DEBUG_FILE_BIT : 0; 131 int debugBits = debugLogging | exchangeLogging | fileLogging; 132 Controller.getInstance(context).serviceLogging(debugBits); 133 //EXCHANGE-REMOVE-SECTION-END 134 } 135 } 136