| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.chrome.browser; | |
| 6 | |
| 7 import android.annotation.SuppressLint; | |
| 8 import android.content.Context; | |
| 9 import android.os.Build; | |
| 10 import android.provider.Settings; | |
| 11 import android.util.Log; | |
| 12 | |
| 13 import org.chromium.base.CommandLine; | |
| 14 | |
| 15 import java.io.File; | |
| 16 | |
| 17 /** | |
| 18 * Provides implementation of command line initialization for Chrome for Android
. | |
| 19 */ | |
| 20 public final class ChromeCommandLineInitUtil { | |
| 21 | |
| 22 private static final String TAG = "ChromeCommandLineInitUtil"; | |
| 23 | |
| 24 /** | |
| 25 * The location of the command line file needs to be in a protected | |
| 26 * directory so requires root access to be tweaked, i.e., no other app in a | |
| 27 * regular (non-rooted) device can change this file's contents. | |
| 28 * See below for debugging on a regular (non-rooted) device. | |
| 29 */ | |
| 30 private static final String COMMAND_LINE_FILE_PATH = "/data/local"; | |
| 31 | |
| 32 /** | |
| 33 * This path (writable by the shell in regular non-rooted "user" builds) is
used when: | |
| 34 * 1) The "debug app" is set to chrome | |
| 35 * and | |
| 36 * 2) ADB is enabled. | |
| 37 * | |
| 38 */ | |
| 39 private static final String COMMAND_LINE_FILE_PATH_DEBUG_APP = "/data/local/
tmp"; | |
| 40 private static final String COMMAND_LINE_FILE = "chrome-command-line"; | |
| 41 | |
| 42 private ChromeCommandLineInitUtil() { | |
| 43 } | |
| 44 | |
| 45 public static void initChromeCommandLine(Context context) { | |
| 46 if (!CommandLine.isInitialized()) { | |
| 47 File commandLineFile = getAlternativeCommandLinePath(context); | |
| 48 if (commandLineFile == null) { | |
| 49 commandLineFile = new File(COMMAND_LINE_FILE_PATH, COMMAND_LINE_
FILE); | |
| 50 } | |
| 51 CommandLine.initFromFile(commandLineFile.getPath()); | |
| 52 } | |
| 53 } | |
| 54 | |
| 55 /** | |
| 56 * Use an alternative path if adb is enabled and the debug app is chrome. | |
| 57 */ | |
| 58 private static File getAlternativeCommandLinePath(Context context) { | |
| 59 File alternativeCommandLineFile = | |
| 60 new File(COMMAND_LINE_FILE_PATH_DEBUG_APP, COMMAND_LINE_FILE); | |
| 61 if (!alternativeCommandLineFile.exists()) return null; | |
| 62 try { | |
| 63 String debugApp = Build.VERSION.SDK_INT < 17 | |
| 64 ? getDebugAppPreJBMR1(context) : getDebugAppJBMR1(context); | |
| 65 | |
| 66 if (debugApp != null | |
| 67 && debugApp.equals(context.getApplicationContext().getPackag
eName())) { | |
| 68 Log.i(TAG, "Using alternative command line file in " | |
| 69 + alternativeCommandLineFile.getPath()); | |
| 70 return alternativeCommandLineFile; | |
| 71 } | |
| 72 } catch (RuntimeException e) { | |
| 73 Log.e(TAG, "Unable to detect alternative command line file"); | |
| 74 } | |
| 75 | |
| 76 return null; | |
| 77 } | |
| 78 | |
| 79 @SuppressLint("NewApi") | |
| 80 private static String getDebugAppJBMR1(Context context) { | |
| 81 boolean adbEnabled = Settings.Global.getInt(context.getContentResolver()
, | |
| 82 Settings.Global.ADB_ENABLED, 0) == 1; | |
| 83 if (adbEnabled) { | |
| 84 return Settings.Global.getString(context.getContentResolver(), | |
| 85 Settings.Global.DEBUG_APP); | |
| 86 } | |
| 87 return null; | |
| 88 } | |
| 89 | |
| 90 @SuppressWarnings("deprecation") | |
| 91 private static String getDebugAppPreJBMR1(Context context) { | |
| 92 boolean adbEnabled = Settings.System.getInt(context.getContentResolver()
, | |
| 93 Settings.System.ADB_ENABLED, 0) == 1; | |
| 94 if (adbEnabled) { | |
| 95 return Settings.System.getString(context.getContentResolver(), | |
| 96 Settings.System.DEBUG_APP); | |
| 97 } | |
| 98 return null; | |
| 99 } | |
| 100 } | |
| OLD | NEW |