Skip to content

Commit

Permalink
Bug 1554256 - Read GeckoView configuration file in release builds whe…
Browse files Browse the repository at this point in the history
…n package is the current Android "debug-app". r=geckoview-reviewers,snorp

Bug 1533385 taught GeckoView to read configuration from a file. But
right now, release APKs don't read that configuration: see the
documentation at See
https://mozilla.github.io/geckoview/tutorials/automation.html#enabling-reading-configuration-from-a-file-for-release-builds.
However, Android has a flag -- the "debug_app" flag -- that Chrome
uses to control this configuration file behaviour, and this commit
makes GeckoView uses that flag as well.

To use this, invoke `adb shell am set-debug-app --persistent PACKAGE`
(see https://developer.android.com/studio/command-line/adb).

Differential Revision: https://phabricator.services.mozilla.com/D32511

--HG--
extra : moz-landing-system : lando
  • Loading branch information
ncalexan committed May 28, 2019
1 parent f2d4188 commit f0748df
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
package org.mozilla.gecko.util;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.provider.Settings;
import android.support.annotation.NonNull;
import android.text.TextUtils;

public class ContextUtils {
Expand Down Expand Up @@ -46,4 +50,23 @@ public static boolean isInstalledFromGooglePlay(final Context context) {

return INSTALLER_GOOGLE_PLAY.equals(installerPackageName);
}

public static boolean isApplicationDebuggable(final @NonNull Context context) {
final ApplicationInfo applicationInfo = context.getApplicationInfo();
return (applicationInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
}

public static boolean isApplicationCurrentDebugApp(final @NonNull Context context) {
final ApplicationInfo applicationInfo = context.getApplicationInfo();

final String currentDebugApp;
if (Build.VERSION.SDK_INT >= 17) {
currentDebugApp = Settings.Global.getString(context.getContentResolver(),
Settings.Global.DEBUG_APP);
} else {
currentDebugApp = Settings.System.getString(context.getContentResolver(),
Settings.System.DEBUG_APP);
}
return applicationInfo.packageName.equals(currentDebugApp);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ServiceInfo;
import android.content.res.Configuration;
Expand All @@ -37,6 +36,7 @@
import org.mozilla.gecko.GeckoThread;
import org.mozilla.gecko.PrefsHelper;
import org.mozilla.gecko.util.BundleEventListener;
import org.mozilla.gecko.util.ContextUtils;
import org.mozilla.gecko.util.DebugConfig;
import org.mozilla.gecko.util.EventCallback;
import org.mozilla.gecko.util.GeckoBundle;
Expand Down Expand Up @@ -264,11 +264,10 @@ private static String getProcessName(final Context context) {
String configFilePath = settings.getConfigFilePath();
if (configFilePath == null) {
// Default to /data/local/tmp/$PACKAGE-geckoview-config.yaml if android:debuggable="true"
// and to not read configuration from a file if android:debuggable="false".
final ApplicationInfo applicationInfo = context.getApplicationInfo();
final boolean isPackageDebuggable = (applicationInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
if (isPackageDebuggable) {
configFilePath = String.format(CONFIG_FILE_PATH_TEMPLATE, applicationInfo.packageName);
// or if this application is the current Android "debug_app", and to not read configuration
// from a file otherwise.
if (ContextUtils.isApplicationDebuggable(context) || ContextUtils.isApplicationCurrentDebugApp(context)) {
configFilePath = String.format(CONFIG_FILE_PATH_TEMPLATE, context.getApplicationInfo().packageName);
}
}

Expand Down

0 comments on commit f0748df

Please sign in to comment.