Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(292)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/ChromeCommandLineInitUtil.java

Issue 1364143002: Move ChromeCommandLineInitUtil to base/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blimp_test
Patch Set: Made sure we actually initialize the command line Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 import org.chromium.base.annotations.SuppressFBWarnings;
15
16 import java.io.File;
17
18 /**
19 * Provides implementation of command line initialization for Chrome for Android .
20 */
21 public final class ChromeCommandLineInitUtil {
22
23 private static final String TAG = "ChromeCommandLineInitUtil";
24
25 /**
26 * The location of the command line file needs to be in a protected
27 * directory so requires root access to be tweaked, i.e., no other app in a
28 * regular (non-rooted) device can change this file's contents.
29 * See below for debugging on a regular (non-rooted) device.
30 */
31 private static final String COMMAND_LINE_FILE_PATH = "/data/local";
32
33 /**
34 * This path (writable by the shell in regular non-rooted "user" builds) is used when:
35 * 1) The "debug app" is set to chrome
36 * and
37 * 2) ADB is enabled.
38 *
39 */
40 private static final String COMMAND_LINE_FILE_PATH_DEBUG_APP = "/data/local/ tmp";
41 private static final String COMMAND_LINE_FILE = "chrome-command-line";
42
43 private ChromeCommandLineInitUtil() {
44 }
45
46 @SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME")
47 public static void initChromeCommandLine(Context context) {
48 if (!CommandLine.isInitialized()) {
49 File commandLineFile = getAlternativeCommandLinePath(context);
50 if (commandLineFile == null) {
51 commandLineFile = new File(COMMAND_LINE_FILE_PATH, COMMAND_LINE_ FILE);
52 }
53 CommandLine.initFromFile(commandLineFile.getPath());
54 }
55 }
56
57 /**
58 * Use an alternative path if adb is enabled and the debug app is chrome.
59 */
60 @SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME")
61 private static File getAlternativeCommandLinePath(Context context) {
62 File alternativeCommandLineFile =
63 new File(COMMAND_LINE_FILE_PATH_DEBUG_APP, COMMAND_LINE_FILE);
64 if (!alternativeCommandLineFile.exists()) return null;
65 try {
66 String debugApp = Build.VERSION.SDK_INT < 17
67 ? getDebugAppPreJBMR1(context) : getDebugAppJBMR1(context);
68
69 if (debugApp != null
70 && debugApp.equals(context.getApplicationContext().getPackag eName())) {
71 Log.i(TAG, "Using alternative command line file in "
72 + alternativeCommandLineFile.getPath());
73 return alternativeCommandLineFile;
74 }
75 } catch (RuntimeException e) {
76 Log.e(TAG, "Unable to detect alternative command line file");
77 }
78
79 return null;
80 }
81
82 @SuppressLint("NewApi")
83 private static String getDebugAppJBMR1(Context context) {
84 boolean adbEnabled = Settings.Global.getInt(context.getContentResolver() ,
85 Settings.Global.ADB_ENABLED, 0) == 1;
86 if (adbEnabled) {
87 return Settings.Global.getString(context.getContentResolver(),
88 Settings.Global.DEBUG_APP);
89 }
90 return null;
91 }
92
93 @SuppressWarnings("deprecation")
94 private static String getDebugAppPreJBMR1(Context context) {
95 boolean adbEnabled = Settings.System.getInt(context.getContentResolver() ,
96 Settings.System.ADB_ENABLED, 0) == 1;
97 if (adbEnabled) {
98 return Settings.System.getString(context.getContentResolver(),
99 Settings.System.DEBUG_APP);
100 }
101 return null;
102 }
103 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698