Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,5 @@ public class RegistrationConstants {
public static final String DEFAULT_HOST_IP = "mosip.registration.audit_default_host_ip";
public static final String DEFAULT_HOST_NAME = "mosip.registration.audit_default_host_name";
public static final String REG_PAK_MAX_CNT_APPRV_LIMIT = "mosip.registration.reg_pak_max_cnt_apprv_limit";
public static final String PACKET_STORE_LOCATION = "mosip.registration.registration_packet_store_location";
}
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ public String getCachedStringFieldsToRetainOnPridFetch(){
public int getCachedIntRegMaxCountApproveLimit(){
return getCachedIntegerGlobalParam(RegistrationConstants.REG_PAK_MAX_CNT_APPRV_LIMIT);
}
public String getCachedStringPacketStoreLocation() {
return globalParamMap.get(RegistrationConstants.PACKET_STORE_LOCATION);
}

/**
* Refresh configuration cache by merging global params with local preferences
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -91,6 +92,7 @@
import io.mosip.registration.packetmanager.spi.PacketWriterService;
import io.mosip.registration.packetmanager.util.DateUtils;
import io.mosip.registration.packetmanager.util.PacketManagerConstant;
import io.mosip.registration.packetmanager.util.StorageUtils;
import lombok.NonNull;

@Singleton
Expand Down Expand Up @@ -643,14 +645,9 @@ public List<Map<String, String>> getAudits() {

private void doPreChecksBeforeRegistration(CenterMachineDto centerMachineDto) throws Exception {
//free space validation
int minSpaceRequiredMB = globalParamRepository.getCachedIntegerDiskSpaceSize();
if (minSpaceRequiredMB == 0) {
minSpaceRequiredMB = DEFAULT_MIN_SPACE_REQUIRED_MB;
if (validatingDiskSpace()) {
throw new ClientCheckedException("PAK_DISK_SPACE_LOW");
}

long externalSpace = context.getExternalCacheDir().getUsableSpace();
if ((externalSpace / (1024 * 1024)) < minSpaceRequiredMB)
throw new ClientCheckedException(context, R.string.err_006);

//is machine and center active
if (centerMachineDto == null || !centerMachineDto.getCenterStatus() || !centerMachineDto.getMachineStatus())
Expand All @@ -677,6 +674,35 @@ private void doPreChecksBeforeRegistration(CenterMachineDto centerMachineDto) th
}
}

private boolean validatingDiskSpace() {
int minSpaceRequiredMB = globalParamRepository.getCachedIntegerDiskSpaceSize();
if (minSpaceRequiredMB <= 0) {
minSpaceRequiredMB = DEFAULT_MIN_SPACE_REQUIRED_MB;
}
long allowedDiskSpaceSizeInBytes = (long) minSpaceRequiredMB * 1024 * 1024;

File actualDiskSpace = StorageUtils.getPacketStorageDir(context);

if (!actualDiskSpace.exists() && !actualDiskSpace.mkdirs()) {
Log.e(TAG, "Packet store directory not available: " + actualDiskSpace.getAbsolutePath());
return true; // treat as low space/unavailable
}
if (!actualDiskSpace.isDirectory() || !actualDiskSpace.canWrite()) {
Log.e(TAG, "Packet store directory not writable: " + actualDiskSpace.getAbsolutePath());
return true; // treat as low space/unavailable
}

long usableSpace = actualDiskSpace.getUsableSpace();
if (usableSpace == 0) {
Log.e(TAG, "Usable space is 0 for path: " + actualDiskSpace.getAbsolutePath());
return true; // treat as low space/unavailable
}

return usableSpace < allowedDiskSpaceSizeInBytes;
}



private byte[] convertImageToPDF(List<byte[]> images) {
try (PDDocument pdDocument = new PDDocument();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import io.mosip.registration.packetmanager.util.ConfigService;
import io.mosip.registration.keymanager.util.CryptoUtil;
import io.mosip.registration.packetmanager.util.PacketKeeper;
import io.mosip.registration.packetmanager.util.StorageUtils;



Expand Down Expand Up @@ -486,22 +487,6 @@ private String validateFilename(String filename, String intendedDir) throws IOEx

private void initPreRegAdapter(Context context) {
this.appContext = context;

String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
String location = ConfigService.getProperty("objectstore.base.location", context);

File file = new File(Environment.getExternalStorageDirectory() + SEPARATOR + location);

if (!file.exists()) {
file.mkdirs();
}

BASE_LOCATION = file.getAbsolutePath();
} else {
Log.e(TAG, "External Storage not mounted");
}
Log.i(TAG, "initLocalClientCryptoService: Initialization call successful");
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#----------------------- Packet Manager --------------------------------------------------
#base location
objectstore.base.location=Documents
objectstore.base.location=packets
#crypto name
objectstore.crypto.name=ObjectStoreCryptoName;
objectstore.adapter.name=PosixAdapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
import javax.inject.Singleton;

import io.mosip.registration.packetmanager.spi.ObjectAdapterService;
import io.mosip.registration.packetmanager.util.ConfigService;
import io.mosip.registration.packetmanager.util.ObjectStoreUtil;
import io.mosip.registration.packetmanager.util.StorageUtils;

/**
* @Author Anshul Vanawat
Expand Down Expand Up @@ -72,22 +72,13 @@ public PosixAdapterServiceImpl(Context appContext, IPacketCryptoService iPacketC

private void initPosixAdapterService(Context context) {
this.appContext = context;

String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
String location = ConfigService.getProperty("objectstore.base.location", context);

File file = new File(Environment.getExternalStorageDirectory() + SEPARATOR + location);

if (!file.exists()) {
file.mkdirs();
}

BASE_LOCATION = file.getAbsolutePath();
File baseDir = StorageUtils.getPacketStorageDir(context);
if (baseDir.exists() || baseDir.mkdirs()) {
BASE_LOCATION = baseDir.getAbsolutePath();
} else {
Log.e(TAG, "External Storage not mounted");
Log.e(TAG, "Failed to initialize packet storage directory: " + baseDir.getAbsolutePath());
BASE_LOCATION = null;
}
Log.i(TAG, "initLocalClientCryptoService: Initialization call successful");
}

@Override
Expand Down Expand Up @@ -218,9 +209,16 @@ private Map<ZipEntry, ByteArrayOutputStream> getAllExistingEntries(InputStream p
private void createContainerZipWithSubPacket(String account, String container, String source, String process, String objectName, InputStream data)
throws IOException {

String state = Environment.getExternalStorageState();
//external storage availability check
if (BASE_LOCATION == null) {
Log.e(TAG, "BASE_LOCATION is not initialized");
return;
}

File baseDir = new File(BASE_LOCATION);
String state = Environment.getExternalStorageState(baseDir);
//storage availability check
if (!Environment.MEDIA_MOUNTED.equals(state)) {
Log.e(TAG, "External storage not mounted. State: " + state + ", Path: " + baseDir.getAbsolutePath());
return;
}

Expand Down
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;
}
}
}
2 changes: 1 addition & 1 deletion assets/l10n/app_ar.arb
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@
"logout_success": "لقد تم تسجيل بنجاح!",
"logout_failure": "حدث خطأ ما، يرجى المحاولة مرة أخرى بعد مرور بعض الوقت",
"go_to_home": "اذهب إلى المنزل",
"errors": "{messages, select, REG_TRY_AGAIN{فشل تسجيل الدخول. حاول مرة أخرى!} REG_INVALID_REQUEST{كلمة المرور غير صحيحة!} REG_MACHINE_NOT_FOUND{لم يتم تسجيل هذا الجهاز بعد. يرجى التواصل مع المسؤول للحصول على المساعدة!} REG_NETWORK_ERROR{فشل تسجيل الدخول. تحقق من اتصال الشبكة!} REG_CRED_EXPIRED{لم يتم العثور على بيانات الاعتماد أو انتهت صلاحيتها. يرجى محاولة تسجيل الدخول عبر الإنترنت!} REG_MACHINE_INACTIVE{الآلة غير نشطة!} REG_CENTER_INACTIVE{المركز غير نشط!} REG_LOGIN_LOCKED{تم الوصول إلى الحد الأقصى لمحاولة تسجيل الدخول. حاول مرة أخرى لاحقا!} KER_SYN_AUTH_001{تعذر الحصول على رمز المصادقة!} PAK_APPRVL_MAX_TIME{الإجراء المطلوب: لقد تجاوزت الحزم المسجلة المعلقة وقت الموافقة المسموح به. يرجى مسح التراكم للمتابعة.} PAK_UPLOAD_MAX_TIME{الإجراء المطلوب: تحميل الحزم أو تصديرها إلى الخادم قبل متابعة التسجيل.} PAK_UPLOAD_MAX_COUNT{الإجراء المطلوب: تم الوصول إلى الحد الأقصى للحزمة. الرجاء تصدير أو تحميل الحزم الموجودة قبل إنشاء تسجيلات جديدة.} REG_PKT_APPRVL_CNT_EXCEED{تم الوصول إلى الحد الأقصى لعدد حزم التسجيل المعلقة للموافقة على العميل. يرجى الموافقة على الحزم أو رفضها قبل متابعة هذا التسجيل.} other{'Some error occurred!'}}",
"errors": "{messages, select, REG_TRY_AGAIN{فشل تسجيل الدخول. حاول مرة أخرى!} REG_INVALID_REQUEST{كلمة المرور غير صحيحة!} REG_MACHINE_NOT_FOUND{لم يتم تسجيل هذا الجهاز بعد. يرجى التواصل مع المسؤول للحصول على المساعدة!} REG_NETWORK_ERROR{فشل تسجيل الدخول. تحقق من اتصال الشبكة!} REG_CRED_EXPIRED{لم يتم العثور على بيانات الاعتماد أو انتهت صلاحيتها. يرجى محاولة تسجيل الدخول عبر الإنترنت!} REG_MACHINE_INACTIVE{الآلة غير نشطة!} REG_CENTER_INACTIVE{المركز غير نشط!} REG_LOGIN_LOCKED{تم الوصول إلى الحد الأقصى لمحاولة تسجيل الدخول. حاول مرة أخرى لاحقا!} KER_SYN_AUTH_001{تعذر الحصول على رمز المصادقة!} PAK_APPRVL_MAX_TIME{الإجراء المطلوب: لقد تجاوزت الحزم المسجلة المعلقة وقت الموافقة المسموح به. يرجى مسح التراكم للمتابعة.} PAK_UPLOAD_MAX_TIME{الإجراء المطلوب: تحميل الحزم أو تصديرها إلى الخادم قبل متابعة التسجيل.} PAK_UPLOAD_MAX_COUNT{الإجراء المطلوب: تم الوصول إلى الحد الأقصى للحزمة. الرجاء تصدير أو تحميل الحزم الموجودة قبل إنشاء تسجيلات جديدة.} PAK_DISK_SPACE_LOW{الحد الأدنى من المساحة المطلوبة غير متوفر لإنشاء الحزمة.} REG_PKT_APPRVL_CNT_EXCEED{تم الوصول إلى الحد الأقصى لعدد حزم التسجيل المعلقة للموافقة على العميل. يرجى الموافقة على الحزم أو رفضها قبل متابعة هذا التسجيل.} other{'Some error occurred!'}}",
"@errors": {
"description": "Error messages",
"placeholders": {
Expand Down
2 changes: 1 addition & 1 deletion assets/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@
"logout_success": "You have been successfully logged out!",
"logout_failure": "Something went wrong, please try again after some time",
"go_to_home": "Go To Home",
"errors": "{messages, select, REG_TRY_AGAIN{Login Failed. Try Again!} REG_INVALID_REQUEST{Password incorrect!} REG_MACHINE_NOT_FOUND{This device has not been onboarded yet. Please reach out to your administrator for assistance!} REG_NETWORK_ERROR{Login failed. Check network connection!} REG_CRED_EXPIRED{Credentials not found or are expired. Please try online login!} REG_MACHINE_INACTIVE{Machine is not active!} REG_CENTER_INACTIVE{Center is not active!} REG_LOGIN_LOCKED{Maximum login attempt limit reached. Try again later!} KER_SYN_AUTH_001{Unable to get Authentication Token!} PAK_APPRVL_MAX_TIME{Action required: Pending registered packets have exceeded the allowed approval time. Please clear the backlog to continue.} PAK_UPLOAD_MAX_TIME{Action required: Upload or export the packets to the server before proceeding with registration.} PAK_UPLOAD_MAX_COUNT{Action required: Packet limit reached. Please export or upload existing packets before creating new registrations.} REG_PKT_APPRVL_CNT_EXCEED{Maximum number of registration packets pending approval on client reached. Please approve or reject packets before proceeding with this registration.} other{'Some error occurred!'}}",
"errors": "{messages, select, REG_TRY_AGAIN{Login Failed. Try Again!} REG_INVALID_REQUEST{Password incorrect!} REG_MACHINE_NOT_FOUND{This device has not been onboarded yet. Please reach out to your administrator for assistance!} REG_NETWORK_ERROR{Login failed. Check network connection!} REG_CRED_EXPIRED{Credentials not found or are expired. Please try online login!} REG_MACHINE_INACTIVE{Machine is not active!} REG_CENTER_INACTIVE{Center is not active!} REG_LOGIN_LOCKED{Maximum login attempt limit reached. Try again later!} KER_SYN_AUTH_001{Unable to get Authentication Token!} PAK_APPRVL_MAX_TIME{Action required: Pending registered packets have exceeded the allowed approval time. Please clear the backlog to continue.} PAK_UPLOAD_MAX_TIME{Action required: Upload or export the packets to the server before proceeding with registration.} PAK_UPLOAD_MAX_COUNT{Action required: Packet limit reached. Please export or upload existing packets before creating new registrations.} PAK_DISK_SPACE_LOW{Minimum required space is not available to create the packet.} REG_PKT_APPRVL_CNT_EXCEED{Maximum number of registration packets pending approval on client reached. Please approve or reject packets before proceeding with this registration.} other{'Some error occurred!'}}",
"@errors": {
"description": "Error messages",
"placeholders": {
Expand Down
Loading