1 /* 2 * Copyright (C) 2017 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.documentsui.base; 18 19 import android.util.Log; 20 import android.util.Pair; 21 22 import com.android.documentsui.Injector; 23 import com.android.documentsui.R; 24 25 /** 26 * Debug menu tools requested by QA Fred. 27 */ 28 public class DebugHelper { 29 private static final String TAG = "DebugHelper"; 30 private static final int[][] code = new int[][] { 31 {19, 19, 20, 20, 21, 22, 21, 22, 30, 29}, 32 {51, 51, 47, 47, 29, 32, 29, 32, 30, 29} 33 }; 34 private static final int[][] colors = new int[][] { 35 {0xFFDB3236, 0xFFB71C1C}, 36 {0xFF3cba54, 0xFF1B5E20}, 37 {0xFFf4c20d, 0xFFF9A825}, 38 {0xFF4885ed, 0xFF0D47A1} 39 }; 40 private static final Pair[] messages = new Pair[]{ 41 new Pair<>("Woof Woof", R.drawable.debug_msg_1), 42 new Pair<>("ワンワン", R.drawable.debug_msg_2) 43 }; 44 45 private boolean debugEnabled = false; 46 private long lastTime = 0; 47 private int position = 0; 48 private int codeIndex = 0; 49 private int colorIndex = 0; 50 private int messageIndex = 0; 51 private Injector<?> mInjector; 52 DebugHelper(Injector<?> injector)53 public DebugHelper(Injector<?> injector) { 54 mInjector = injector; 55 } 56 getNextColors()57 public int[] getNextColors() { 58 assert (mInjector.features.isDebugSupportEnabled()); 59 60 if (colorIndex == colors.length) { 61 colorIndex = 0; 62 } 63 64 return colors[colorIndex++]; 65 } 66 getNextMessage()67 public Pair<String, Integer> getNextMessage() { 68 assert (mInjector.features.isDebugSupportEnabled()); 69 70 if (messageIndex == messages.length) { 71 messageIndex = 0; 72 } 73 74 return messages[messageIndex++]; 75 } 76 debugCheck(long time, int keyCode)77 public void debugCheck(long time, int keyCode) { 78 if (time == lastTime) { 79 return; 80 } 81 lastTime = time; 82 83 if (position == 0) { 84 for (int i = 0; i < code.length; i++) { 85 if (keyCode == code[i][0]) { 86 codeIndex = i; 87 break; 88 } 89 } 90 } 91 92 if (keyCode == code[codeIndex][position]) { 93 position++; 94 } else if (position > 2 || (position == 2 && keyCode != code[codeIndex][0])) { 95 position = 0; 96 } 97 98 if (position == code[codeIndex].length) { 99 position = 0; 100 debugEnabled = !debugEnabled; 101 // Actions is content-scope, so it can technically be null, though 102 // not likely. 103 if (mInjector.actions != null) { 104 mInjector.actions.setDebugMode(debugEnabled); 105 } 106 107 if (Shared.VERBOSE) { 108 Log.v(TAG, "Debug mode " + (debugEnabled ? "on" : "off")); 109 } 110 } 111 } 112 } 113