Skip to content

Commit

Permalink
Check for more potential NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilZ-cwm6 committed Jul 20, 2022
1 parent 768c66d commit 16910c0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ static public ArrayList<String> getLocalMountpointList2(Context c) {
return new_ml;
}

// not used, fix File NPE before use
@SuppressLint("SdCardPath")
static public ArrayList<String> getLocalMountPointList(Context c) {
String pkg_name=c.getClass().getPackage().getName();
Expand Down Expand Up @@ -353,19 +354,20 @@ static public ArrayList<String> getLocalMountPointList(Context c) {
addMountPointPrimaryAndSecondary("/storage/external_SD", ml, pkg_name);

// File[] ext_dirs =ContextCompat.getExternalFilesDirs(c, null);
File[] ext_dirs =c.getExternalFilesDirs(null);
if (ext_dirs!=null) {
for (int i=0;i<ext_dirs.length;i++) {
if (ext_dirs[i]!=null && ext_dirs[i].getPath()!=null) {
if (!ext_dirs[i].getPath().startsWith(primary_esd)) {
boolean found=false;
for(int j=0;j<ml.size();j++) {
if (ext_dirs[i].getPath().equals(ml.get(j))) {
found=true;
File[] ext_dirs = c.getExternalFilesDirs(null);
if (ext_dirs != null) {
for (int i=0; i < ext_dirs.length; i++) {
if (ext_dirs[i] != null) {
String ext_dir_path = ext_dirs[i].getPath();
if (ext_dir_path != null && !ext_dir_path.startsWith(primary_esd)) {
boolean found = false;
for(int j=0; j < ml.size(); j++) {
if (ext_dir_path.equals(ml.get(j))) {
found = true;
break;
}
}
if (!found) ml.add(ext_dirs[i].getPath());
if (!found) ml.add(ext_dir_path);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1466,9 +1466,14 @@ public void showDialog(Context c, FragmentManager fm, Fragment frag, NotifyEvent
ft.commitAllowingStateLoss();
mNotifyUpdateLogOption=ntfy;
} else {
File lf=c.getExternalFilesDirs(null)[0];
String fp = "";
File[] fl=c.getExternalFilesDirs(null);
if (fl != null) {
File lf=fl[0];
if (lf != null) fp = lf.getPath(); // internal storage app specific dir
}
MessageDialogFragment mdf=MessageDialogFragment.newInstance(false, "E",
c.getString(R.string.msgs_log_can_not_start_log_mgmt), "file="+lf);
c.getString(R.string.msgs_log_can_not_start_log_mgmt), "file="+fp);
mdf.showDialog(fm, mdf, null);
}
};
Expand Down
33 changes: 22 additions & 11 deletions app/src/main/java/com/sentaroh/android/Utilities3/SafManager3.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,13 @@ private ArrayList<SafStorage3> buildSafFileList() {
if (!item_svi.isDuplicate) {
if (isScopedStorageMode()) {
rt=SafFile3.fromTreeUri(mContext, Uri.parse(SAF_FILE_DOCUMENT_TREE_URI_PREFIX+item_svi.uuid+"%3A"));
if (rt.exists()) {//Internal storage, SDCARD or USB
if (rt != null && rt.exists()) {//Internal storage, SDCARD or USB
SafStorage3 sli=new SafStorage3();
sli.description=item_svi.description;
sli.uuid=item_svi.uuid;
sli.saf_file =rt;
sli.isSafFile=true;
sli.appDirectory=getAppSpecificDirectory(mContext, item_svi.uuid);
sli.appDirectory=getAppSpecificDirectory(mContext, item_svi.uuid);
saf_list.add(sli);
}
} else {
Expand All @@ -243,9 +243,12 @@ private ArrayList<SafStorage3> buildSafFileList() {
sli.isSafFile=false;
sli.appDirectory=getAppSpecificDirectory(mContext, item_svi.uuid);
sli.appMountpoint=baseMp;
String fp=mContext.getExternalFilesDirs(null)[0].getPath();
sli.saf_file=new SafFile3(mContext, fp.substring(0, fp.indexOf("/Android/data")));
saf_list.add(sli);
File[] fl=mContext.getExternalFilesDirs(null);
if (fl != null && fl[0] != null) {
String fp=fl[0].getPath();
sli.saf_file=new SafFile3(mContext, fp.substring(0, fp.indexOf("/Android/data")));
saf_list.add(sli);
}
} else {//SDCARD or USB
File lf=new File(SafFile3.SAF_FILE_EXTERNAL_STORAGE_PREFIX+ item_svi.uuid);
if (lf.exists()) {
Expand All @@ -272,13 +275,16 @@ private ArrayList<SafStorage3> buildSafFileList() {
sli.description=item_svi.description;
sli.uuid=SAF_FILE_PRIMARY_UUID;
sli.isSafFile=false;
sli.appDirectory=mContext.getExternalFilesDirs(null)[0].getPath();
sli.appMountpoint=baseMp;
sli.saf_file=new SafFile3(mContext, SAF_FILE_PRIMARY_STORAGE_PREFIX);
saf_list.add(sli);
File[] fl=mContext.getExternalFilesDirs(null);
if (fl != null && fl[0] != null) {
sli.appDirectory=fl[0].getPath();
sli.appMountpoint=baseMp;
sli.saf_file=new SafFile3(mContext, SAF_FILE_PRIMARY_STORAGE_PREFIX);
saf_list.add(sli);
}
} else {
rt=SafFile3.fromTreeUri(mContext, Uri.parse(SAF_FILE_DOCUMENT_TREE_URI_PREFIX+item_svi.uuid+"%3A"));
if (rt.exists()) {
if (rt != null && rt.exists()) {
SafStorage3 sli=new SafStorage3();
sli.description=item_svi.description;
sli.uuid=item_svi.uuid;
Expand Down Expand Up @@ -316,7 +322,12 @@ public int compare(SafStorage3 l1, SafStorage3 r1) {

static private String getAppSpecificDirectory(Context c, String uuid) {
String app_dir = null;
File[] fl =c.getExternalFilesDirs(null); // null for no subdirectory
if (uuid == null) {
log.debug("getAppSpecificDirectory Error: null uuid specified");
return app_dir;
}

File[] fl = c.getExternalFilesDirs(null); // null for no subdirectory
if (fl != null) {
if (uuid.equals(SAF_FILE_PRIMARY_UUID) && fl[0] != null) {
app_dir=fl[0].getPath(); // -> /storage/emulated/0/Android/data/com.sentaroh.android.SMBSync3/files/
Expand Down

0 comments on commit 16910c0

Please sign in to comment.