-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New implementation for getCurrentProcessName #427
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,9 +15,7 @@ | |
*/ | ||
package org.acra; | ||
|
||
import android.app.ActivityManager; | ||
import android.app.Application; | ||
import android.content.Context; | ||
import android.content.SharedPreferences; | ||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; | ||
import android.os.Build; | ||
|
@@ -34,8 +32,10 @@ | |
import org.acra.prefs.PrefUtils; | ||
import org.acra.prefs.SharedPreferencesFactory; | ||
import org.acra.util.ApplicationStartupProcessor; | ||
import org.acra.util.IOUtils; | ||
|
||
import java.util.List; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
|
||
/** | ||
* Use this class to initialize the crash reporting feature using | ||
|
@@ -50,7 +50,7 @@ | |
public final class ACRA { | ||
private ACRA(){} | ||
|
||
public static final boolean DEV_LOGGING = false; // Should be false for release. | ||
public static /*non-final*/ boolean DEV_LOGGING = false; // Should be false for release. | ||
|
||
public static final String LOG_TAG = ACRA.class.getSimpleName(); | ||
|
||
|
@@ -172,7 +172,7 @@ public static void init(@NonNull Application app, @NonNull ACRAConfiguration con | |
*/ | ||
public static void init(@NonNull Application app, @NonNull ACRAConfiguration config, boolean checkReportsOnApplicationStart){ | ||
|
||
final boolean senderServiceProcess = isACRASenderServiceProcess(app); | ||
final boolean senderServiceProcess = isACRASenderServiceProcess(); | ||
if (senderServiceProcess) { | ||
if (ACRA.DEV_LOGGING) log.d(LOG_TAG, "Not initialising ACRA to listen for uncaught Exceptions as this is the SendWorker process and we only send reports, we don't capture them to avoid infinite loops"); | ||
} | ||
|
@@ -269,25 +269,21 @@ public static boolean isInitialised() { | |
* @return true if the current process is the process running the SenderService. | ||
* NB this assumes that your SenderService is configured to used the default ':acra' process. | ||
*/ | ||
public static boolean isACRASenderServiceProcess(@NonNull Application app) { | ||
final String processName = getCurrentProcessName(app); | ||
public static boolean isACRASenderServiceProcess() { | ||
final String processName = getCurrentProcessName(); | ||
if (ACRA.DEV_LOGGING) log.d(LOG_TAG, "ACRA processName='" + processName + "'"); | ||
return (processName != null) && processName.equals(ACRA_PRIVATE_PROCESS_NAME); | ||
//processName sometimes (or always?) starts with the package name, so we use endsWith instead of equals | ||
return (processName != null) && processName.endsWith(ACRA_PRIVATE_PROCESS_NAME); | ||
} | ||
|
||
@Nullable | ||
private static String getCurrentProcessName(@NonNull Application app) { | ||
private static String getCurrentProcessName() { | ||
final int processId = android.os.Process.myPid(); | ||
final ActivityManager manager = (ActivityManager) app.getSystemService(Context.ACTIVITY_SERVICE); | ||
List<ActivityManager.RunningAppProcessInfo> processInfos = manager.getRunningAppProcesses(); | ||
if (processInfos != null) { | ||
for (final ActivityManager.RunningAppProcessInfo processInfo : processInfos) { | ||
if (processInfo.pid == processId) { | ||
return processInfo.processName; | ||
} | ||
} | ||
try { | ||
return IOUtils.streamToString(new FileInputStream("/proc/"+processId+"/cmdline")).trim(); | ||
} catch (IOException e) { | ||
return null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we also need to keep the original solution as backup in case they are using Exposed (as per the note on the StackOverflow post). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've tested it with Xposed. No changes. As stated in the comments on the solution, this problem is outdated. |
||
} | ||
return null; | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WHy change this from equals to endsWidth? equals is much more precise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that when run on an 6.0 device, the process name is prepended with the package name. (I haven't tested on other versions, this might just be normal for the new getCurrentProcessName.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, just add an inline comment to that effect so that we know why when looking at it later.