Merge branch 'clean-up-sdcard-swap' into 'master'
Clean up sdcard swap See merge request fdroid/fdroidclient!775
This commit is contained in:
		
						commit
						e4537a4271
					
				@ -85,11 +85,15 @@ class NearbyViewBinder {
 | 
			
		||||
                    Environment.isExternalStorageRemovable(activity.getExternalFilesDir("")));
 | 
			
		||||
            File[] dirs = activity.getExternalFilesDirs("");
 | 
			
		||||
            if (dirs != null) {
 | 
			
		||||
                for (File f : dirs) {
 | 
			
		||||
                    if (f != null && Environment.isExternalStorageRemovable(f)) {
 | 
			
		||||
                        // remove Android/data/org.fdroid.fdroid/files to get root
 | 
			
		||||
                        externalStorage = f.getParentFile().getParentFile().getParentFile().getParentFile();
 | 
			
		||||
                        break;
 | 
			
		||||
                for (File dir : dirs) {
 | 
			
		||||
                    if (dir != null && Environment.isExternalStorageRemovable(dir)) {
 | 
			
		||||
                        String state = Environment.getExternalStorageState(dir);
 | 
			
		||||
                        if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)
 | 
			
		||||
                                || 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();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        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);
 | 
			
		||||
            View readExternalStorage = swapView.findViewById(R.id.readExternalStorage);
 | 
			
		||||
            readExternalStorage.setVisibility(View.VISIBLE);
 | 
			
		||||
@ -109,26 +117,20 @@ class NearbyViewBinder {
 | 
			
		||||
                @RequiresApi(api = 21)
 | 
			
		||||
                @Override
 | 
			
		||||
                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
 | 
			
		||||
                            && !externalStorage.canRead()
 | 
			
		||||
                            && (externalStorage == null || !externalStorage.canRead())
 | 
			
		||||
                            && PackageManager.PERMISSION_GRANTED
 | 
			
		||||
                            != ContextCompat.checkSelfPermission(activity, writeExternalStorage)) {
 | 
			
		||||
                        ActivityCompat.requestPermissions(activity, new String[]{writeExternalStorage},
 | 
			
		||||
                                MainActivity.REQUEST_STORAGE_PERMISSIONS);
 | 
			
		||||
                    } else {
 | 
			
		||||
                        Toast.makeText(activity,
 | 
			
		||||
                                activity.getString(R.string.scan_removable_storage_toast, externalStorage),
 | 
			
		||||
                                Toast.LENGTH_SHORT).show();
 | 
			
		||||
                        SDCardScannerService.scan(activity);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -26,7 +26,6 @@ import android.net.Uri;
 | 
			
		||||
import android.support.annotation.Nullable;
 | 
			
		||||
import android.text.TextUtils;
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
 | 
			
		||||
import org.fdroid.fdroid.Utils;
 | 
			
		||||
import org.fdroid.fdroid.data.Apk;
 | 
			
		||||
 | 
			
		||||
@ -91,9 +90,11 @@ class ApkVerifier {
 | 
			
		||||
        Utils.debugLog(TAG, "expectedTargetSdkVersion: " + expectedTargetSdkVersion);
 | 
			
		||||
        if (expectedTargetSdkVersion == Apk.SDK_VERSION_MIN_VALUE) {
 | 
			
		||||
            // 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) {
 | 
			
		||||
            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));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -56,6 +56,7 @@ import org.fdroid.fdroid.R;
 | 
			
		||||
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.views.AppDetailsActivity;
 | 
			
		||||
import org.fdroid.fdroid.views.ManageReposActivity;
 | 
			
		||||
import org.fdroid.fdroid.views.apps.AppListActivity;
 | 
			
		||||
@ -248,6 +249,11 @@ public class MainActivity extends AppCompatActivity implements BottomNavigationB
 | 
			
		||||
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
 | 
			
		||||
        if (requestCode == REQUEST_LOCATION_PERMISSIONS) {
 | 
			
		||||
            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);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -60,6 +60,7 @@
 | 
			
		||||
    <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="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
 | 
			
		||||
        and USB thumb drives
 | 
			
		||||
    </string>
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user