Skip to content

Commit

Permalink
Protect against NPE on process util process check
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgyoung committed Sep 21, 2017
1 parent 41e6f06 commit 71b0c95
Showing 1 changed file with 8 additions and 3 deletions.
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 71b0c95

Please sign in to comment.