Merge branch 'clean-up-sdcard-swap' into 'master'

Clean up sdcard swap

See merge request fdroid/fdroidclient!775
This commit is contained in:
Hans-Christoph Steiner 2018-12-25 22:32:23 +00:00
commit e4537a4271
4 changed files with 29 additions and 19 deletions

View File

@ -85,11 +85,15 @@ class NearbyViewBinder {
Environment.isExternalStorageRemovable(activity.getExternalFilesDir(""))); Environment.isExternalStorageRemovable(activity.getExternalFilesDir("")));
File[] dirs = activity.getExternalFilesDirs(""); File[] dirs = activity.getExternalFilesDirs("");
if (dirs != null) { if (dirs != null) {
for (File f : dirs) { for (File dir : dirs) {
if (f != null && Environment.isExternalStorageRemovable(f)) { if (dir != null && Environment.isExternalStorageRemovable(dir)) {
// remove Android/data/org.fdroid.fdroid/files to get root String state = Environment.getExternalStorageState(dir);
externalStorage = f.getParentFile().getParentFile().getParentFile().getParentFile(); if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)
break; || Environment.MEDIA_MOUNTED.equals(state)) {
// remove Android/data/org.fdroid.fdroid/files to get root
externalStorage = dir.getParentFile().getParentFile().getParentFile().getParentFile();
break;
}
} }
} }
} }
@ -100,7 +104,11 @@ class NearbyViewBinder {
externalStorage = Environment.getExternalStorageDirectory(); externalStorage = Environment.getExternalStorageDirectory();
} }
if (externalStorage != null) { final String writeExternalStorage = Manifest.permission.WRITE_EXTERNAL_STORAGE;
if (externalStorage != null
|| PackageManager.PERMISSION_GRANTED
!= ContextCompat.checkSelfPermission(activity, writeExternalStorage)) {
nearbySplash.setVisibility(View.GONE); nearbySplash.setVisibility(View.GONE);
View readExternalStorage = swapView.findViewById(R.id.readExternalStorage); View readExternalStorage = swapView.findViewById(R.id.readExternalStorage);
readExternalStorage.setVisibility(View.VISIBLE); readExternalStorage.setVisibility(View.VISIBLE);
@ -109,26 +117,20 @@ class NearbyViewBinder {
@RequiresApi(api = 21) @RequiresApi(api = 21)
@Override @Override
public void onClick(View v) { public void onClick(View v) {
File storage = externalStorage.getParentFile();
File[] files = storage.listFiles();
String msg = "";
if (files != null) for (File f : files) {
msg += "|" + f.getName();
}
Toast.makeText(activity, msg, Toast.LENGTH_LONG).show();
final String writeExternalStorage = Manifest.permission.WRITE_EXTERNAL_STORAGE;
if (Build.VERSION.SDK_INT >= 23 if (Build.VERSION.SDK_INT >= 23
&& !externalStorage.canRead() && (externalStorage == null || !externalStorage.canRead())
&& PackageManager.PERMISSION_GRANTED && PackageManager.PERMISSION_GRANTED
!= ContextCompat.checkSelfPermission(activity, writeExternalStorage)) { != ContextCompat.checkSelfPermission(activity, writeExternalStorage)) {
ActivityCompat.requestPermissions(activity, new String[]{writeExternalStorage}, ActivityCompat.requestPermissions(activity, new String[]{writeExternalStorage},
MainActivity.REQUEST_STORAGE_PERMISSIONS); MainActivity.REQUEST_STORAGE_PERMISSIONS);
} else { } else {
Toast.makeText(activity,
activity.getString(R.string.scan_removable_storage_toast, externalStorage),
Toast.LENGTH_SHORT).show();
SDCardScannerService.scan(activity); SDCardScannerService.scan(activity);
} }
} }
}); });
} }
} }
} }

View File

@ -26,7 +26,6 @@ import android.net.Uri;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import org.fdroid.fdroid.Utils; import org.fdroid.fdroid.Utils;
import org.fdroid.fdroid.data.Apk; import org.fdroid.fdroid.data.Apk;
@ -91,9 +90,11 @@ class ApkVerifier {
Utils.debugLog(TAG, "expectedTargetSdkVersion: " + expectedTargetSdkVersion); Utils.debugLog(TAG, "expectedTargetSdkVersion: " + expectedTargetSdkVersion);
if (expectedTargetSdkVersion == Apk.SDK_VERSION_MIN_VALUE) { if (expectedTargetSdkVersion == Apk.SDK_VERSION_MIN_VALUE) {
// NOTE: In old fdroidserver versions, targetSdkVersion was not stored inside the repo! // NOTE: In old fdroidserver versions, targetSdkVersion was not stored inside the repo!
Log.w(TAG, "Skipping check for targetSdkVersion, not available in this repo!"); Log.w(TAG, "Skipping check for targetSdkVersion, not available in this app or repo!");
} else if (localTargetSdkVersion != expectedTargetSdkVersion) { } else if (localTargetSdkVersion != expectedTargetSdkVersion) {
throw new ApkVerificationException("TargetSdkVersion of apk file is not the expected targetSdkVersion!"); throw new ApkVerificationException(
String.format("TargetSdkVersion of apk file (%d) is not the expected targetSdkVersion (%d)!",
localTargetSdkVersion, expectedTargetSdkVersion));
} }
} }

View File

@ -56,6 +56,7 @@ import org.fdroid.fdroid.R;
import org.fdroid.fdroid.UpdateService; import org.fdroid.fdroid.UpdateService;
import org.fdroid.fdroid.Utils; import org.fdroid.fdroid.Utils;
import org.fdroid.fdroid.data.NewRepoConfig; import org.fdroid.fdroid.data.NewRepoConfig;
import org.fdroid.fdroid.localrepo.SDCardScannerService;
import org.fdroid.fdroid.views.AppDetailsActivity; import org.fdroid.fdroid.views.AppDetailsActivity;
import org.fdroid.fdroid.views.ManageReposActivity; import org.fdroid.fdroid.views.ManageReposActivity;
import org.fdroid.fdroid.views.apps.AppListActivity; import org.fdroid.fdroid.views.apps.AppListActivity;
@ -248,6 +249,11 @@ public class MainActivity extends AppCompatActivity implements BottomNavigationB
super.onRequestPermissionsResult(requestCode, permissions, grantResults); super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == REQUEST_LOCATION_PERMISSIONS) { if (requestCode == REQUEST_LOCATION_PERMISSIONS) {
startActivity(new Intent(this, SwapWorkflowActivity.class)); startActivity(new Intent(this, SwapWorkflowActivity.class));
} else if (requestCode == REQUEST_STORAGE_PERMISSIONS) {
Toast.makeText(this,
this.getString(R.string.scan_removable_storage_toast, ""),
Toast.LENGTH_SHORT).show();
SDCardScannerService.scan(this);
} }
} }

View File

@ -60,6 +60,7 @@
<string name="local_repo_name_summary">The advertised title of your local repo: %s</string> <string name="local_repo_name_summary">The advertised title of your local repo: %s</string>
<string name="local_repo_https_on">Use encrypted HTTPS:// connection for local repo</string> <string name="local_repo_https_on">Use encrypted HTTPS:// connection for local repo</string>
<string name="scan_removable_storage_title">Scan removable storage</string> <string name="scan_removable_storage_title">Scan removable storage</string>
<string name="scan_removable_storage_toast">Scanning %s…</string>
<string name="scan_removable_storage_summary">Look for package repos on removable storage like SD Cards <string name="scan_removable_storage_summary">Look for package repos on removable storage like SD Cards
and USB thumb drives and USB thumb drives
</string> </string>