Commit 5dcb92b8 authored by Jonathan Klee's avatar Jonathan Klee
Browse files

Merge branch 'persistent' into 'v1-nougat'

Introduce EdriveApplication class

See merge request e/apps/eDrive!61
parents 63c1893b 357ffca8
Pipeline #155292 passed with stage
in 3 minutes and 57 seconds
......@@ -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"
......
......@@ -18,6 +18,8 @@ http://www.gnu.org/licenses/gpl.html
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<application
android:name=".EdriveApplication"
android:persistent="true"
android:allowBackup="true"
android:icon="@mipmap/ic_eelo"
android:label="@string/app_name"
......@@ -62,14 +64,6 @@ http://www.gnu.org/licenses/gpl.html
android:enabled="true" />
<service android:name=".services.OperationManagerService" />
<!-- Receivers -->
<receiver
android:name=".receivers.BootCompleteReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<receiver
android:name=".receivers.BatteryStateReceiver"
android:enabled="true">
......
/*
* 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.");
}
}
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);
}
}
}
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment