Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
1. [fix] haiwen#985
2.[modify] WRITE_EXTERNAL_STORAGE Modified to MANAGE_EXTERNAL_STORAGE in BrowserActivity
3. fix other bugs
  • Loading branch information
zhwanng committed Nov 3, 2023
1 parent 8413967 commit 916536e
Show file tree
Hide file tree
Showing 17 changed files with 296 additions and 62 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ lint.xml
# Gradle files
.gradle/
**/build/
gradle.properties

# Local configuration file (sdk path, etc)
local.properties
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId 'com.seafile.seadroid2'
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 138
versionName "2.3.5"
versionCode 139
versionName "2.3.6"
multiDexEnabled true
resValue "string", "authorities", applicationId + '.cameraupload.provider'
resValue "string", "account_type", "com.seafile.seadroid2.account.api2"
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@
<!--android 9.0 FOREGROUND_SERVICE -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.READ_SYNC_STATS" />

<!-- <uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" />-->

<application
android:name="com.seafile.seadroid2.SeadroidApplication"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build;
import android.os.FileUtils;
import android.provider.Settings.Secure;
import android.text.TextUtils;
import android.util.Log;
Expand Down Expand Up @@ -633,7 +634,6 @@ private File getFileFromLink(String dlink, String path, String localPath, String
return null;
}
return file;

} catch (SeafException e) {
throw e;
} catch (UnsupportedEncodingException e) {
Expand Down
16 changes: 9 additions & 7 deletions app/src/main/java/com/seafile/seadroid2/data/DataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,16 @@ public File getLocalRepoFile(String repoName, String repoID, String path) throws
if (TextUtils.isEmpty(repoID)) {
return null;
}

String repoDir = getRepoDir(repoName, repoID);
if (TextUtils.isEmpty(repoDir)) {
return null;
}
String localPath = Utils.pathJoin(repoDir, path);

//build valid file path and name
localPath = com.seafile.seadroid2.util.FileUtils.buildValidFilePathName(localPath);

File parentDir = new File(Utils.getParentPath(localPath));
if (!parentDir.exists()) {
// TODO should check if the directory creation succeeds
Expand Down Expand Up @@ -459,8 +464,7 @@ private void deleteOldDirentContent(String repoID, String dir) {
dbHelper.removeCachedDirents(repoID, dir);
}

public synchronized File getFile(String repoName, String repoID, String path,
ProgressMonitor monitor) throws SeafException {
public synchronized File getFile(String repoName, String repoID, String path, ProgressMonitor monitor) throws SeafException {

String cachedFileID = null;
SeafCachedFile cf = getCachedFile(repoName, repoID, path);
Expand All @@ -485,9 +489,7 @@ public synchronized File getFile(String repoName, String repoID, String path,
}
}

public synchronized File getFileByBlocks(String repoName, String repoID, String path, long fileSize,
ProgressMonitor monitor) throws SeafException, IOException, JSONException, NoSuchAlgorithmException {

public synchronized File getFileByBlocks(String repoName, String repoID, String path, long fileSize, ProgressMonitor monitor) throws SeafException, IOException, JSONException, NoSuchAlgorithmException {
String cachedFileID = null;
SeafCachedFile cf = getCachedFile(repoName, repoID, path);
File localFile = getLocalRepoFile(repoName, repoID, path);
Expand Down Expand Up @@ -1154,8 +1156,8 @@ public String getLastPullToRefreshTime(String whichFragment) {
* @return json format strings of searched result
* @throws SeafException
*/
public String search(String query,int page, int pageSize) throws SeafException {
String json = sc.searchLibraries(query, page,pageSize);
public String search(String query, int page, int pageSize) throws SeafException {
String json = sc.searchLibraries(query, page, pageSize);
return json;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,7 @@ public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
onUpgrade(db, oldVersion, newVersion);
}

public SeafCachedFile getFileCacheItem(String repoID,
String path, DataManager dataManager) {
public SeafCachedFile getFileCacheItem(String repoID, String path, DataManager dataManager) {
String[] projection = {
FILECACHE_COLUMN_ID,
FILECACHE_COLUMN_FILEID,
Expand Down Expand Up @@ -425,8 +424,7 @@ public boolean repoDirExists(Account account, String dir) {
return exist;
}

public void saveRepoDirMapping(Account account,
String repoID, String dir) {
public void saveRepoDirMapping(Account account, String repoID, String dir) {
String log = String.format("Saving repo dir mapping: account = %s(%s) "
+ "repoID = %s"
+ "dir = %s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,22 @@ private void startBackupFolder(String parentPath, String filePath) {
}

Utils.utilsLogInfo(false, "parentPath ->" + parentPath);
Utils.utilsLogInfo(false, "filePath ->" + fb.getFilePath());
Utils.utilsLogInfo(false, "localPath ->" + fb.getFilePath());

FolderBackupInfo fileInfo = databaseHelper.getBackupFileInfo(
repoConfig.getRepoID(),
fb.getFilePath(),
String.valueOf(fb.getSimpleSize()));
//
if (fileInfo != null && !TextUtils.isEmpty(fileInfo.filePath)) {
Utils.utilsLogInfo(false, "file not exists ->" + fileInfo.filePath);
Utils.utilsLogInfo(false, "db exists ->" + fileInfo.filePath);
Utils.utilsLogInfo(false, "---------------");
continue;
}

Utils.utilsLogInfo(false, "uploadFile ->" + fb.getFilePath());
Utils.utilsLogInfo(false, "---------------");

int taskID = txService.addTaskToSourceQue(Utils.TRANSFER_FOLDER_TAG, currentAccount,
repoConfig.getRepoID(), repoConfig.getRepoName(), parentPath,
fb.getFilePath(), false, false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.seafile.seadroid2.transfer;

import android.os.AsyncTask;
import android.os.FileUtils;

import com.seafile.seadroid2.SeafException;
import com.seafile.seadroid2.account.Account;

Expand Down Expand Up @@ -28,6 +30,7 @@ public TransferTask(String source, int taskID, Account account, String repoName,
this.account = account;
this.repoName = repoName;
this.repoID = repoID;

this.path = path;
this.state = TaskState.INIT;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.IBinder;
import android.provider.MediaStore;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
Expand All @@ -25,6 +27,7 @@
import android.view.View;
import android.view.Window;
import android.widget.FrameLayout;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.Toolbar;
Expand All @@ -39,6 +42,7 @@
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.viewpager.widget.ViewPager;

import com.blankj.utilcode.util.ToastUtils;
import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.tabs.TabLayout;
import com.google.common.collect.Lists;
Expand Down Expand Up @@ -406,15 +410,13 @@ public void onPageScrollStateChanged(int state) {

requestServerInfo();

requestReadExternalStoragePermission();
// requestReadExternalStoragePermission();
checkAndRequestManageStoragePermission();

Utils.startCameraSyncJob(this);
syncCamera();
}

public FrameLayout getmContainer() {
return mContainer;
}

private void finishAndStartAccountsActivity() {
Intent newIntent = new Intent(this, AccountsActivity.class);
newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Expand Down Expand Up @@ -566,18 +568,49 @@ public void onTaskSuccess() {
return super.onOptionsItemSelected(item);
}

private void checkAndRequestManageStoragePermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
if (!Environment.isExternalStorageManager()) {
new AlertDialog.Builder(this)
.setMessage(R.string.permission_manage_exteral_storage_rationale)
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
intent.setData(Uri.parse("package:" + BrowserActivity.this.getPackageName()));
startActivity(intent);
}
})
.show();
}

} else {
requestReadExternalStoragePermission();
}
}

/**
* If the user is running Android 6.0 (API level 23) or later, the user has to grant your app its permissions while they are running the app
* <p>
* If the user is running Android 6.0 (API level 23) or later,
* the user has to grant your app its permissions while they are running the app.
* </p>
* <p>
* Requests the WRITE_EXTERNAL_STORAGE permission.
* If the permission has been denied previously, a SnackBar will prompt the user to grant the
* permission, otherwise it is requested directly.
* </p>
*/
private void requestReadExternalStoragePermission() {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {

Snackbar.make(mLayout,
R.string.permission_read_exteral_storage_rationale,
Expand All @@ -603,6 +636,7 @@ public void onClick(View view) {
}
}


/**
* Callback received when a permissions request has been completed.
*/
Expand Down Expand Up @@ -1648,8 +1682,7 @@ public void downloadFile(String dir, String fileName) {
filePath);

if (!txService.hasDownloadNotifProvider()) {
DownloadNotificationProvider provider = new DownloadNotificationProvider(txService.getDownloadTaskManager(),
txService);
DownloadNotificationProvider provider = new DownloadNotificationProvider(txService.getDownloadTaskManager(), txService);
txService.saveDownloadNotifProvider(provider);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package com.seafile.seadroid2.ui.adapter;

import android.graphics.Bitmap;
import androidx.annotation.Nullable;
import androidx.viewpager.widget.PagerAdapter;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;

import androidx.annotation.Nullable;
import androidx.viewpager.widget.PagerAdapter;

import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.engine.GlideException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,6 @@ public void navToDirectory(boolean forceRefresh, boolean restorePosition) {
if (nav.getDirPath().equals(BrowserActivity.ACTIONBAR_PARENT_PATH)) {
mActivity.setUpButtonTitle(nav.getRepoName());
} else

mActivity.setUpButtonTitle(nav.getDirPath().substring(
nav.getDirPath().lastIndexOf(BrowserActivity.ACTIONBAR_PARENT_PATH) + 1));
}
Expand Down Expand Up @@ -477,7 +476,6 @@ public void startTimer() {
isTimerStarted = true;
Log.d(DEBUG_TAG, "timer started");
mTimer.postDelayed(new Runnable() {

@Override
public void run() {
if (mActivity == null) return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
package com.seafile.seadroid2.ui.fragment;

import android.Manifest;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceCategory;
import android.preference.PreferenceScreen;

import androidx.appcompat.app.AlertDialog;

import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
Expand Down Expand Up @@ -319,8 +324,7 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
cFolderBackupCategory.removePreference(cBackupFolderState);
SettingsManager.instance().saveFolderAutomaticBackup(false);
} else {

XXPermissions.with(getActivity()).permission(Permission.MANAGE_EXTERNAL_STORAGE).request(new OnPermissionCallback() {
XXPermissions.with(requireContext()).permission(Permission.MANAGE_EXTERNAL_STORAGE).request(new OnPermissionCallback() {

@Override
public void onGranted(List<String> permissions, boolean all) {
Expand All @@ -334,10 +338,10 @@ public void onGranted(List<String> permissions, boolean all) {
@Override
public void onDenied(List<String> permissions, boolean never) {
if (never) {
Toast.makeText(getActivity(), mActivity.getString(R.string.authorization_storage_permission), Toast.LENGTH_LONG).show();
Toast.makeText(requireContext(), mActivity.getString(R.string.authorization_storage_permission), Toast.LENGTH_LONG).show();
XXPermissions.startPermissionActivity(getActivity(), permissions);
} else {
Toast.makeText(getActivity(), mActivity.getString(R.string.get_storage_permission_failed), Toast.LENGTH_LONG).show();
Toast.makeText(requireContext(), mActivity.getString(R.string.get_storage_permission_failed), Toast.LENGTH_LONG).show();
((CheckBoxPreference) findPreference(SettingsManager.FOLDER_BACKUP_SWITCH_KEY)).setChecked(false);
}
}
Expand All @@ -358,11 +362,7 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
cUploadCategory.removePreference(cUploadAdvancedScreen);
cameraManager.disableCameraUpload();
} else {
// Intent intent = new Intent(mActivity, CameraUploadConfigActivity.class);
// intent.putExtra(CAMERA_UPLOAD_BOTH_PAGES, true);
// startActivityForResult(intent, CHOOSE_CAMERA_UPLOAD_REQUEST);
XXPermissions.with(getActivity()).permission(Permission.MANAGE_EXTERNAL_STORAGE).request(new OnPermissionCallback() {

XXPermissions.with(requireContext()).permission(Permission.MANAGE_EXTERNAL_STORAGE).request(new OnPermissionCallback() {
@Override
public void onGranted(List<String> permissions, boolean all) {
if (all) {
Expand All @@ -375,11 +375,11 @@ public void onGranted(List<String> permissions, boolean all) {
@Override
public void onDenied(List<String> permissions, boolean never) {
if (never) {
Toast.makeText(getActivity(), mActivity.getString(R.string.authorization_storage_permission), Toast.LENGTH_LONG).show();
XXPermissions.startPermissionActivity(getActivity(), permissions);
Toast.makeText(requireContext(), mActivity.getString(R.string.authorization_storage_permission), Toast.LENGTH_LONG).show();
XXPermissions.startPermissionActivity(requireContext(), permissions);
} else {
Toast.makeText(getActivity(), mActivity.getString(R.string.get_storage_permission_failed), Toast.LENGTH_LONG).show();
((CheckBoxPreference) findPreference(SettingsManager.FOLDER_BACKUP_SWITCH_KEY)).setChecked(false);
Toast.makeText(requireContext(), mActivity.getString(R.string.get_storage_permission_failed), Toast.LENGTH_LONG).show();
((CheckBoxPreference) findPreference(SettingsManager.CAMERA_UPLOAD_SWITCH_KEY)).setChecked(false);
}
}
});
Expand Down
Loading

0 comments on commit 916536e

Please sign in to comment.