diff --git a/README.md b/README.md index ca74e2ae5a3688d448bbead364e26d83166febc6..1bb0f953d66c9dbfad827671d6814e47076d0e63 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,9 @@ - Vincent (vincent.bourgmayer@e.email) - Frank +### Install + +Since the application is persistent, you won't be able to reinstall the app with a regular `adb install -r` command. You will have to `pm uninstall foundation.e.drive` before reinstalling the application. ### Notes: To disable All the synchronisation, go into your account and disable BOTH: "application settings" AND "Photos and videos" diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 792349d703886c8c4885fe7e627ed72d1c327faa..1d75965c7850bf15274201ac5f483a0e8e22f751 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -18,6 +18,8 @@ http://www.gnu.org/licenses/gpl.html - - - - - - diff --git a/app/src/main/java/foundation/e/drive/EdriveApplication.java b/app/src/main/java/foundation/e/drive/EdriveApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..993cfe0674609f239ced629e6e7a97c17a15893f --- /dev/null +++ b/app/src/main/java/foundation/e/drive/EdriveApplication.java @@ -0,0 +1,67 @@ +/* + * Copyright © ECORP SAS 2022. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Public License v3.0 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/gpl.html + */ + +package foundation.e.drive; + +import android.accounts.Account; +import android.accounts.AccountManager; +import android.app.Application; +import android.content.Context; +import android.content.SharedPreferences; +import android.util.Log; + +import foundation.e.drive.utils.AppConstants; +import foundation.e.drive.utils.CommonUtils; +import foundation.e.drive.utils.JobUtils; + +/** + * Class representing the eDrive application. + * It is instantiated before any other class. + */ +public class EdriveApplication extends Application { + + private static final String TAG = "EdriveApplication"; + + @Override + public void onCreate() { + super.onCreate(); + + Log.i(TAG, "Starting"); + + SharedPreferences prefs = getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE); + if (prefs.getString(AccountManager.KEY_ACCOUNT_NAME, null) != null) { + prefs.edit().putBoolean(AppConstants.KEY_OMS_IS_WORKING, false).commit(); + scheduleScannerJob(); + } else { + Account mAccount = CommonUtils.getAccount(getString(R.string.eelo_account_type), AccountManager.get(this)); + if (mAccount != null) { + String accountName = mAccount.name; + String accountType = mAccount.type; + + prefs.edit().putString(AccountManager.KEY_ACCOUNT_NAME, accountName) + .putBoolean(AppConstants.KEY_OMS_IS_WORKING, false) + .putString(AccountManager.KEY_ACCOUNT_TYPE, accountType) + .apply(); + + scheduleScannerJob(); + } + } + } + + private void scheduleScannerJob() { + if (!JobUtils.isScannerJobRegistered(this)) { + JobUtils.scheduleScannerJob(this); + } + } + + @Override + public void onLowMemory() { + super.onLowMemory(); + Log.w(TAG, "System is low on memory. Application might get killed by the system."); + } +} diff --git a/app/src/main/java/foundation/e/drive/receivers/BootCompleteReceiver.java b/app/src/main/java/foundation/e/drive/receivers/BootCompleteReceiver.java deleted file mode 100644 index a996fe1cd5ea67b6bd33fcbf62386828b6fdbe87..0000000000000000000000000000000000000000 --- a/app/src/main/java/foundation/e/drive/receivers/BootCompleteReceiver.java +++ /dev/null @@ -1,61 +0,0 @@ -package foundation.e.drive.receivers; - -import android.accounts.Account; -import android.accounts.AccountManager; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.util.Log; - -import foundation.e.drive.R; -import foundation.e.drive.services.ObserverService; -import foundation.e.drive.utils.AppConstants; -import foundation.e.drive.utils.CommonUtils; -import foundation.e.drive.utils.JobUtils; - - -public class BootCompleteReceiver extends BroadcastReceiver { - private final static String TAG = BootCompleteReceiver.class.getSimpleName(); - - @Override - public void onReceive(Context context, Intent intent) { - Log.i(TAG, "onReceive"); - String intentAction = intent.getAction(); - - if (intentAction == null) { - Log.e(TAG, "intent Action is null"); - } else if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) { - SharedPreferences prefs = context.getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE); - if (prefs.getString(AccountManager.KEY_ACCOUNT_NAME, null) != null) { - //If user account is registered - prefs.edit().putBoolean(AppConstants.KEY_OMS_IS_WORKING, false).commit(); - - if (!JobUtils.isScannerJobRegistered(context)) { - //scanner job isn't registered then register it - JobUtils.scheduleScannerJob(context); - } - - } else { - - Account mAccount = CommonUtils.getAccount(context.getString(R.string.eelo_account_type), AccountManager.get(context)); - - if (mAccount != null) { - String accountName = mAccount.name; - String accountType = mAccount.type; - - //If data come from intent, store them into pref because there aren't stored - prefs.edit().putString(AccountManager.KEY_ACCOUNT_NAME, accountName) - .putBoolean(AppConstants.KEY_OMS_IS_WORKING, false) - .putString(AccountManager.KEY_ACCOUNT_TYPE, accountType) - .apply(); - - if (!JobUtils.isScannerJobRegistered(context)) { - //scanner job isn't registered then register it - JobUtils.scheduleScannerJob(context); - } - } - } - } - } -}