Commit e28f16d0 authored by Mohit Mali's avatar Mohit Mali
Browse files

- Removed sharedUserId

- Fix issue when eDrive doesn't recognise User account after update
parent fbe57ef8
Pipeline #62058 canceled with stage
in 10 seconds
......@@ -7,20 +7,21 @@ http://www.gnu.org/licenses/gpl.html
-->
<!-- @author Vincent Bourgmayer -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="foundation.e.drive"
android:sharedUserId="android.uid.system" >
package="foundation.e.drive">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <!-- needed for PersistedJob -->
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <!-- needed for PersistedJob -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
<permission android:name="android.permission.FORCE_STOP_PACKAGES"
<permission
android:name="android.permission.FORCE_STOP_PACKAGES"
android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
android:protectionLevel="signature"/>
android:protectionLevel="signature" />
<application
android:allowBackup="true"
......@@ -29,55 +30,64 @@ http://www.gnu.org/licenses/gpl.html
android:roundIcon="@mipmap/ic_eelo_round">
<!-- Providers -->
<provider
android:authorities="foundation.e.drive.providers.MediasSyncProvider"
android:name=".providers.MediasSyncProvider"
android:label="Pictures and videos"
android:authorities="foundation.e.drive.providers.MediasSyncProvider"
android:enabled="true"
android:exported="true"/>
android:exported="true"
android:label="Pictures and videos" />
<provider
android:authorities="foundation.e.drive.providers.SettingsSyncProvider"
android:name=".providers.SettingsSyncProvider"
android:label="Application settings"
android:authorities="foundation.e.drive.providers.SettingsSyncProvider"
android:enabled="true"
android:exported="true"/>
android:exported="true"
android:label="Application settings" />
<!-- Services -->
<service android:name=".services.InitializerService"
<service
android:name=".services.InitializerService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="drive.services.InitializerService" />
</intent-filter>
</service>
<service android:name=".services.ResetService"
<service
android:name=".services.ResetService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="drive.services.ResetService" />
</intent-filter>
</service>
<service android:name=".jobs.ScannerJob"
<service
android:name=".jobs.ScannerJob"
android:permission="android.permission.BIND_JOB_SERVICE" />
<service android:name=".services.ObserverService"
android:enabled="true"/>
<service android:name=".services.OperationManagerService"/>
<service
android:name=".services.ObserverService"
android:enabled="true" />
<service android:name=".services.OperationManagerService" />
<!-- Receivers -->
<receiver android:name=".receivers.BootCompleteReceiver"
<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">
<receiver
android:name=".receivers.BatteryStateReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BATTERY_LOW"/>
<action android:name="android.intent.action.BATTERY_OKAY"/>
<action android:name="android.intent.action.BATTERY_LOW" />
<action android:name="android.intent.action.BATTERY_OKAY" />
</intent-filter>
</receiver>
<receiver android:name=".receivers.PackageEventReceiver" android:enabled="true">
<receiver
android:name=".receivers.PackageEventReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
</intent-filter>
</receiver>
</application>
......
......@@ -8,6 +8,7 @@
package foundation.e.drive.receivers;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.BroadcastReceiver;
import android.content.Context;
......@@ -15,32 +16,52 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;
import foundation.e.drive.R;
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();
String intentAction = intent.getAction();
if(intentAction == null){
if (intentAction == null) {
Log.e(TAG, "intent Action is null");
} else if ( intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
} 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 (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)) {
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);
}
}
}
}
}
......
......@@ -22,13 +22,17 @@ import android.net.Uri;
import android.support.annotation.NonNull;
import android.util.Log;
import android.webkit.MimeTypeMap;
import com.owncloud.android.lib.common.OwnCloudBasicCredentials;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientFactory;
import com.owncloud.android.lib.common.accounts.AccountUtils;
import com.owncloud.android.lib.resources.files.FileUtils;
import java.io.File;
import foundation.e.drive.receivers.ScreenOffReceiver;
import static foundation.e.drive.utils.AppConstants.MEDIASYNC_PROVIDER_AUTHORITY;
import static foundation.e.drive.utils.AppConstants.SETTINGSYNC_PROVIDER_AUTHORITY;
......@@ -43,29 +47,31 @@ public abstract class CommonUtils {
/**
* Set ServiceUncaughtExceptionHandler to be the MainThread Exception Handler
* Or update the service which use it
*
* @param service current service
*/
public static void setServiceUnCaughtExceptionHandler(Service service){
public static void setServiceUnCaughtExceptionHandler(Service service) {
Thread.UncaughtExceptionHandler defaultUEH = Thread.getDefaultUncaughtExceptionHandler();
if(defaultUEH.getClass().getSimpleName().equals(ServiceExceptionHandler.class.getSimpleName())){
if (defaultUEH.getClass().getSimpleName().equals(ServiceExceptionHandler.class.getSimpleName())) {
Log.d("ObserverService", "ServiceExceptionHandler already set!");
((ServiceExceptionHandler) defaultUEH).setService(service);
}else{
} else {
Thread.setDefaultUncaughtExceptionHandler(new ServiceExceptionHandler(service));
}
}
/**
* Unregister from screeOffReceiver component
*
* @param context app context
* @return true if unregistration was successful or false if it encounter an exception
*/
public static boolean unregisterScreenOff(Context context){
public static boolean unregisterScreenOff(Context context) {
try {
Log.d("TAG", "unregisterReceiver(screenOffReceiver)");
context.unregisterReceiver(ScreenOffReceiver.getInstance());
}catch(IllegalArgumentException e){
} catch (IllegalArgumentException e) {
Log.w(TAG, "Can't unregister screenOffReceiver ");
return false;
}
......@@ -75,47 +81,68 @@ public abstract class CommonUtils {
/**
* This method retrieve Account corresponding to account's name and type
*
* @param accountName Account Name, shouldn't be null
* @param accountType account type
* @param am Account Manager
* @return Account or null if not found
*/
public static Account getAccount(@NonNull String accountName, String accountType, @NonNull AccountManager am){
public static Account getAccount(@NonNull String accountName, String accountType, @NonNull AccountManager am) {
Account[] accounts = am.getAccountsByType(accountType);
for(int i = -1, size = accounts.length; ++i < size;){
if(accounts[i].name.equals( accountName )){
for (int i = -1, size = accounts.length; ++i < size; ) {
if (accounts[i].name.equals(accountName)) {
return accounts[i];
}
}
return null;
}
/**
* This method retrieve Account corresponding to account's type
*
* @param accountType account type
* @param am Account Manager
* @return Account or null if not found
*/
public static Account getAccount(String accountType, @NonNull AccountManager am) {
  • you introduced a second function with the same name

  • while the pipeline reports linter issues, it wouldn't fail because of it

  • Using the same name for a function is not a problem if the signature (parameters or return type) is different, which is the case here

  • thanks for educating me on this one - I mostly read interpreter languages and was unaware of the concept of function overloading

Please register or sign in to reply
Account[] accounts = am.getAccounts();
for (int i = -1, size = accounts.length; ++i < size; ) {
if (accounts[i].type.equals(accountType)) {
return accounts[i];
}
}
return null;
}
/**
* Say if synchronisation is allowed
*
* @param account Account used for synchronisation
* @param syncedFileStateIsMedia true if the concerned syncedFileState is a media's type element, false if it is a settings's type element
* @return
*/
public static boolean isThisSyncAllowed(Account account, boolean syncedFileStateIsMedia){
return ( syncedFileStateIsMedia && isMediaSyncEnabled(account) )
|| ( !syncedFileStateIsMedia && isSettingsSyncEnabled(account) ) ;
public static boolean isThisSyncAllowed(Account account, boolean syncedFileStateIsMedia) {
return (syncedFileStateIsMedia && isMediaSyncEnabled(account))
|| (!syncedFileStateIsMedia && isSettingsSyncEnabled(account));
}
/**
* Say if Media Sync is enabled in account
*
* @param account Concerned account
* @return true if media sync enabled
*/
public static boolean isMediaSyncEnabled(Account account){
public static boolean isMediaSyncEnabled(Account account) {
return ContentResolver.getSyncAutomatically(account, MEDIASYNC_PROVIDER_AUTHORITY);
}
/**
* Say if Settings Sync is enabled in account
*
* @param account Concerned account
* @return true if enabled
*/
public static boolean isSettingsSyncEnabled(Account account){
public static boolean isSettingsSyncEnabled(Account account) {
return ContentResolver.getSyncAutomatically(account, SETTINGSYNC_PROVIDER_AUTHORITY);
}
......@@ -130,10 +157,10 @@ public abstract class CommonUtils {
try {
serverUri = Uri.parse(AccountUtils.getBaseUrlForAccount(context, account));
oc = OwnCloudClientFactory.createOwnCloudClient(serverUri, context, true);
oc.setCredentials(new OwnCloudBasicCredentials(account.name, AccountManager.get(context).getPassword(account) ) );
oc.setCredentials(new OwnCloudBasicCredentials(account.name, AccountManager.get(context).getPassword(account)));
}catch (Exception e){
Log.e(TAG, "Can\'t parse serverPath to Uri : "+e.toString() );
} catch (Exception e) {
Log.e(TAG, "Can\'t parse serverPath to Uri : " + e.toString());
oc = null;
}
return oc;
......@@ -144,15 +171,16 @@ public abstract class CommonUtils {
/**
* Return name of a file from its access path
*
* @param path File name will be extracted from this path. Do not provide directory path
* @return String, the last part after separator of path or null if invalid path has been provided
*/
public static String getFileNameFromPath(String path) {
try{
try {
String[] splittedString = path.split(FileUtils.PATH_SEPARATOR);
return splittedString[splittedString.length - 1];
}catch(Exception e){
Log.e(TAG, e.toString() );
} catch (Exception e) {
Log.e(TAG, e.toString());
return null;
}
}
......@@ -237,22 +265,23 @@ public abstract class CommonUtils {
/**
* Used for debug
* @dev-only
*
* @param f File to debug
* @return String showing value of file's properties
* @dev-only
*/
public static String debugFile(File f) {
return "File name: "+f.getName()
+"\n File exist?: "+f.exists()
+"\n File absolute path: "+f.getAbsolutePath()
+"\n File path: "+f.getPath()
+"\n File length: "+f.length()
+"\n File last modif: "+f.lastModified()
+"\n File readable?: "+f.canRead()
+"\n File writable?: "+f.canWrite()
+"\n File is file?: "+f.isFile()
+"\n File is Dir?: "+f.isDirectory()
+"\n File can be read?: "+f.canRead()
+"\n File can be written?: "+f.canWrite();
return "File name: " + f.getName()
+ "\n File exist?: " + f.exists()
+ "\n File absolute path: " + f.getAbsolutePath()
+ "\n File path: " + f.getPath()
+ "\n File length: " + f.length()
+ "\n File last modif: " + f.lastModified()
+ "\n File readable?: " + f.canRead()
+ "\n File writable?: " + f.canWrite()
+ "\n File is file?: " + f.isFile()
+ "\n File is Dir?: " + f.isDirectory()
+ "\n File can be read?: " + f.canRead()
+ "\n File can be written?: " + f.canWrite();
}
}
\ No newline at end of file
<resources>
<string name="app_name">/e/ Drive</string>
<string name="eelo_account_type" translatable="false">e.foundation.webdav.eelo</string>
</resources>
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