-
Notifications
You must be signed in to change notification settings - Fork 72
RCF-1302 implemented logic for packet storage location #672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
58b0110
RCF-1302 implemented logic for packet storage location
MadhuMosip aaf2f81
resolved code rabbit reviews
MadhuMosip 6bc213d
Merge branch 'develop' of https://github.com/MadhuMosip/android-regis…
MadhuMosip a3c4e31
Resolved coderabbit review comments
MadhuMosip File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
android/packetmanager/src/main/assets/packetmanagerconfig.properties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...id/packetmanager/src/main/java/io/mosip/registration/packetmanager/util/StorageUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package io.mosip.registration.packetmanager.util; | ||
|
|
||
| import android.content.Context; | ||
| import android.os.Environment; | ||
| import android.util.Log; | ||
|
|
||
| import java.io.File; | ||
|
|
||
| public class StorageUtils { | ||
| private static final String TAG = "StorageUtils"; | ||
|
|
||
| public static File getPacketStorageDir(Context context) { | ||
| String location = ConfigService.getProperty("objectstore.base.location", context); | ||
| if (location == null) { | ||
| location = "packets"; | ||
| } | ||
|
|
||
| // 1. Try SD card Documents folder | ||
| File baseDir = getSDCardDir(context, location); | ||
| if (baseDir != null && ensureDirWritable(baseDir)) { | ||
| return baseDir; | ||
| } | ||
|
|
||
| // 2. Try Primary Shared Documents folder (Legacy/Scoped Storage might restrict this) | ||
| baseDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS), location); | ||
| if (ensureDirWritable(baseDir)) { | ||
| return baseDir; | ||
| } | ||
|
|
||
| // 3. Fallback to App-private external storage | ||
| baseDir = context.getExternalFilesDir(location); | ||
| if (baseDir != null && ensureDirWritable(baseDir)) { | ||
| return baseDir; | ||
| } | ||
|
|
||
| // 4. Ultimate fallback to App internal storage | ||
| baseDir = new File(context.getFilesDir(), location); | ||
| ensureDirWritable(baseDir); | ||
| return baseDir; | ||
| } | ||
|
|
||
| private static File getSDCardDir(Context context, String location) { | ||
| File[] externalFilesDirs = context.getExternalFilesDirs(null); | ||
| if (externalFilesDirs != null) { | ||
| for (File file : externalFilesDirs) { | ||
| if (file != null && Environment.isExternalStorageRemovable(file)) { | ||
| try { | ||
| String path = file.getAbsolutePath(); | ||
| int androidIndex = path.indexOf("/Android/data/"); | ||
| if (androidIndex != -1) { | ||
| String sdRoot = path.substring(0, androidIndex); | ||
| return new File(new File(sdRoot, "Documents"), location); | ||
| } | ||
| } catch (Exception e) { | ||
| Log.e(TAG, "Error calculating SD root: " + file.getAbsolutePath(), e); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| private static boolean ensureDirWritable(File dir) { | ||
| try { | ||
| if (!dir.exists() && !dir.mkdirs()) { | ||
| return false; | ||
| } | ||
| return dir.canWrite(); | ||
| } catch (Exception e) { | ||
| Log.e(TAG, "Error ensuring directory writability: " + dir.getAbsolutePath(), e); | ||
| return false; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.