Bug 1510615 - Replace hardcoded /data/data paths or supress lint warning where not replaceable r=geckoview-reviewers,snorp
authorowlishDeveloper <bugzeeeeee@gmail.com>
Thu, 26 Mar 2020 17:26:21 +0000
changeset 520616 03fc2ea7048c15e40088c7f617e5ded13ab313d8
parent 520615 eeb6b2a3ca38e0ecedd18db5d77315ba19c0b67a
child 520617 8c3923411926cff9032863848aaf7eadffbec433
push id37254
push usernerli@mozilla.com
push dateFri, 27 Mar 2020 04:48:07 +0000
treeherdermozilla-central@2d758b42bd73 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgeckoview-reviewers, snorp
bugs1510615
milestone76.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1510615 - Replace hardcoded /data/data paths or supress lint warning where not replaceable r=geckoview-reviewers,snorp Differential Revision: https://phabricator.services.mozilla.com/D67980
mobile/android/geckoview/src/main/java/org/mozilla/gecko/CrashHandler.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/mozglue/GeckoLoader.java
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/CrashHandler.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/CrashHandler.java
@@ -1,15 +1,16 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko;
 
+import android.annotation.SuppressLint;
 import android.app.Service;
 import android.content.Context;
 import android.content.Intent;
 import android.content.pm.PackageInfo;
 import android.content.pm.PackageManager;
 import android.net.Uri;
 import android.os.Build;
 import android.os.Bundle;
@@ -371,16 +372,17 @@ public class CrashHandler implements Thr
 
     /**
      * Report an exception to Socorro.
      *
      * @param thread The exception thread
      * @param exc An exception
      * @return Whether the exception was successfully reported
      */
+    @SuppressLint("SdCardPath")
     protected boolean reportException(final Thread thread, final Throwable exc) {
         final Context context = getAppContext();
         final String id = UUID.randomUUID().toString();
 
         // Use the cache directory under the app directory to store crash files.
         final File dir;
         if (context != null) {
             dir = context.getCacheDir();
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/mozglue/GeckoLoader.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/mozglue/GeckoLoader.java
@@ -5,16 +5,17 @@
 
 package org.mozilla.gecko.mozglue;
 
 import org.mozilla.gecko.GeckoAppShell;
 import org.mozilla.gecko.annotation.JNITarget;
 import org.mozilla.gecko.annotation.RobocopTarget;
 import org.mozilla.gecko.util.HardwareUtils;
 
+import android.annotation.SuppressLint;
 import android.content.Context;
 import android.os.Build;
 import android.os.Environment;
 import android.util.Log;
 
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.InputStream;
@@ -317,33 +318,35 @@ public final class GeckoLoader {
     }
 
     private static String getLoadDiagnostics(final Context context, final String lib) {
         final String androidPackageName = context.getPackageName();
 
         final StringBuilder message = new StringBuilder("LOAD ");
         message.append(lib);
 
+        final String packageDataDir = context.getApplicationInfo().dataDir;
+
         // These might differ. If so, we know why the library won't load!
         HardwareUtils.init(context);
         message.append(": ABI: " + HardwareUtils.getLibrariesABI() + ", " + getCPUABI());
-        message.append(": Data: " + context.getApplicationInfo().dataDir);
+        message.append(": Data: " + packageDataDir);
 
         try {
             final boolean appLibExists = new File("/data/app-lib/" + androidPackageName + "/lib" + lib + ".so").exists();
-            final boolean dataDataExists = new File("/data/data/" + androidPackageName + "/lib/lib" + lib + ".so").exists();
+            final boolean dataDataExists = new File(packageDataDir + "/lib/lib" + lib + ".so").exists();
             message.append(", ax=" + appLibExists);
             message.append(", ddx=" + dataDataExists);
         } catch (Throwable e) {
             message.append(": ax/ddx fail, ");
         }
 
         try {
-            final String dashOne = "/data/data/" + androidPackageName + "-1";
-            final String dashTwo = "/data/data/" + androidPackageName + "-2";
+            final String dashOne = packageDataDir + "-1";
+            final String dashTwo = packageDataDir + "-2";
             final boolean dashOneExists = new File(dashOne).exists();
             final boolean dashTwoExists = new File(dashTwo).exists();
             message.append(", -1x=" + dashOneExists);
             message.append(", -2x=" + dashTwoExists);
         } catch (Throwable e) {
             message.append(", dash fail, ");
         }
 
@@ -402,16 +405,17 @@ public final class GeckoLoader {
                 Log.wtf(LOGTAG, "Library doesn't exist when it should.");
             }
 
             // We failed. Return the original cause.
             return e;
         }
     }
 
+    @SuppressLint("SdCardPath")
     public static void doLoadLibrary(final Context context, final String lib) {
         final Throwable e = doLoadLibraryExpected(context, lib);
         if (e == null) {
             // Success.
             return;
         }
 
         // If we're in a mismatched UID state (Bug 1042935 Comment 16) there's really