Skip to content

Commit

Permalink
Merge pull request #598 from AltBeacon/fix-null-pointer-on-process-utils
Browse files Browse the repository at this point in the history
Protect against NPE on process util process check
  • Loading branch information
davidgyoung authored Oct 14, 2017
2 parents 41e6f06 + a41da6d commit 3941c8f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### Development

Bug Fixes:
- Fix NullPointerException in ProcessUtils. (#598, David G. Young)
- Fix ConcurrentModificationException crashing app on Android 8 when monitored regions are
changed at the same time the app shifts from active scanning to passive scanning.
(#578, David G. Young)
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/org/altbeacon/beacon/utils/ProcessUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import android.content.Context;
import android.support.annotation.NonNull;

import java.util.List;

/**
* Created by dyoung on 3/10/17.
*
Expand All @@ -20,9 +22,12 @@ public ProcessUtils(@NonNull Context context) {

public String getProcessName() {
ActivityManager manager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()) {
if (processInfo.pid == getPid()) {
return processInfo.processName;
List<ActivityManager.RunningAppProcessInfo> processes = manager.getRunningAppProcesses();
if (processes != null) {
for (ActivityManager.RunningAppProcessInfo processInfo : processes) {
if (processInfo.pid == getPid()) {
return processInfo.processName;
}
}
}
return null;
Expand Down

0 comments on commit 3941c8f

Please sign in to comment.