Merge branch 'suite-of-crash-fixes' into 'master'

Suite of crash fixes

See merge request fdroid/fdroidclient!810
This commit is contained in:
Hans-Christoph Steiner 2019-03-29 06:08:50 +00:00
commit 9ed4fe8c64
7 changed files with 43 additions and 28 deletions

View File

@ -60,8 +60,17 @@ class MainViewController extends RecyclerView.ViewHolder {
new CategoriesViewBinder(activity, frame);
}
/**
* {@link android.os.Environment#isExternalStorageRemovable()} sometimes
* throughs {@link IllegalArgumentException}s when it can't find the
* storage.
*/
public void bindSwapView() {
try {
new NearbyViewBinder(activity, frame);
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
}
/**

View File

@ -81,8 +81,6 @@ class NearbyViewBinder {
});
if (Build.VERSION.SDK_INT >= 21) {
Log.i(TAG, "Environment.isExternalStorageRemovable(activity.getExternalFilesDir(\"\")) " +
Environment.isExternalStorageRemovable(activity.getExternalFilesDir("")));
File[] dirs = activity.getExternalFilesDirs("");
if (dirs != null) {
for (File dir : dirs) {

View File

@ -288,9 +288,9 @@ public class SwapAppsView extends ListView implements
@Override
public void onChange(boolean selfChange) {
Activity activity = getActivity();
if (activity != null) {
if (activity != null && app != null) {
app = AppProvider.Helper.findSpecificApp(
getActivity().getContentResolver(),
activity.getContentResolver(),
app.packageName,
app.repoId,
AppMetadataTable.Cols.ALL);

View File

@ -19,7 +19,6 @@
package org.fdroid.fdroid;
import android.app.AlarmManager;
import android.app.IntentService;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.job.JobInfo;
@ -33,8 +32,6 @@ import android.content.IntentFilter;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.Process;
import android.os.SystemClock;
import android.support.annotation.NonNull;
@ -87,7 +84,6 @@ public class UpdateService extends JobIntentService {
private static final int NOTIFY_ID_UPDATING = 0;
private static UpdateService updateService;
private static Handler toastHandler;
private NotificationManager notificationManager;
private NotificationCompat.Builder notificationBuilder;
@ -391,22 +387,6 @@ public class UpdateService extends JobIntentService {
}
}
/**
* In order to send a {@link Toast} from a {@link IntentService}, we have to do these tricks.
*/
private void sendNoInternetToast() {
if (toastHandler == null) {
toastHandler = new Handler(Looper.getMainLooper());
}
toastHandler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),
R.string.warning_no_internet, Toast.LENGTH_SHORT).show();
}
});
}
private static boolean isLocalRepoAddress(String address) {
return address != null &&
(address.startsWith(BluetoothDownloader.SCHEME)
@ -453,7 +433,7 @@ public class UpdateService extends JobIntentService {
if (!foundLocalRepo) {
Utils.debugLog(TAG, "No internet, cannot update");
if (manualUpdate) {
sendNoInternetToast();
Utils.showToastFromService(this, getString(R.string.warning_no_internet), Toast.LENGTH_SHORT);
}
return;
}

View File

@ -27,6 +27,8 @@ import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.StatFs;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@ -42,6 +44,7 @@ import android.text.style.TypefaceSpan;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.widget.Toast;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
@ -101,6 +104,8 @@ public final class Utils {
private static Pattern safePackageNamePattern;
private static Handler toastHandler;
public static final String FALLBACK_ICONS_DIR = "/icons/";
/*
@ -578,7 +583,8 @@ public final class Utils {
Date result;
try {
result = format.parse(str);
} catch (ParseException e) {
} catch (ArrayIndexOutOfBoundsException | NumberFormatException | ParseException e) {
e.printStackTrace();
result = fallback;
}
return result;
@ -839,4 +845,21 @@ public final class Utils {
Utils.debugLog(logTag, "[" + duration + "ms] " + message);
}
}
/**
* In order to send a {@link Toast} from a {@link android.app.Service}, we
* have to do these tricks.
*/
public static void showToastFromService(final Context context, final String msg, final int length) {
if (toastHandler == null) {
toastHandler = new Handler(Looper.getMainLooper());
}
toastHandler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(context.getApplicationContext(), msg, length).show();
}
});
}
}

View File

@ -1112,7 +1112,10 @@ public class App extends ValueObject implements Comparable<App>, Parcelable {
}
eventType = xml.nextToken();
}
} catch (PackageManager.NameNotFoundException | IOException | XmlPullParserException e) {
} catch (PackageManager.NameNotFoundException
| IOException
| XmlPullParserException
| NumberFormatException e) {
Log.e(TAG, "Could not get min/max sdk version", e);
}
if (targetSdkVersion < minSdkVersion) {

View File

@ -57,6 +57,7 @@ import org.fdroid.fdroid.UpdateService;
import org.fdroid.fdroid.Utils;
import org.fdroid.fdroid.data.NewRepoConfig;
import org.fdroid.fdroid.localrepo.SDCardScannerService;
import org.fdroid.fdroid.net.WifiStateChangeService;
import org.fdroid.fdroid.views.AppDetailsActivity;
import org.fdroid.fdroid.views.ManageReposActivity;
import org.fdroid.fdroid.views.apps.AppListActivity;
@ -249,6 +250,7 @@ public class MainActivity extends AppCompatActivity implements BottomNavigationB
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { // NOCHECKSTYLE LineLength
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == REQUEST_LOCATION_PERMISSIONS) {
WifiStateChangeService.start(this, null);
startActivity(new Intent(this, SwapWorkflowActivity.class));
} else if (requestCode == REQUEST_STORAGE_PERMISSIONS) {
Toast.makeText(this,