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 ...@@ -7,20 +7,21 @@ http://www.gnu.org/licenses/gpl.html
--> -->
<!-- @author Vincent Bourgmayer --> <!-- @author Vincent Bourgmayer -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="foundation.e.drive" package="foundation.e.drive">
android:sharedUserId="android.uid.system" >
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_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.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <!-- needed for PersistedJob --> <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.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS"/> <uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" /> <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:permissionGroup="android.permission-group.SYSTEM_TOOLS"
android:protectionLevel="signature"/> android:protectionLevel="signature" />
<application <application
android:allowBackup="true" android:allowBackup="true"
...@@ -29,55 +30,64 @@ http://www.gnu.org/licenses/gpl.html ...@@ -29,55 +30,64 @@ http://www.gnu.org/licenses/gpl.html
android:roundIcon="@mipmap/ic_eelo_round"> android:roundIcon="@mipmap/ic_eelo_round">
<!-- Providers --> <!-- Providers -->
<provider <provider
android:authorities="foundation.e.drive.providers.MediasSyncProvider"
android:name=".providers.MediasSyncProvider" android:name=".providers.MediasSyncProvider"
android:label="Pictures and videos" android:authorities="foundation.e.drive.providers.MediasSyncProvider"
android:enabled="true" android:enabled="true"
android:exported="true"/> android:exported="true"
android:label="Pictures and videos" />
<provider <provider
android:authorities="foundation.e.drive.providers.SettingsSyncProvider"
android:name=".providers.SettingsSyncProvider" android:name=".providers.SettingsSyncProvider"
android:label="Application settings" android:authorities="foundation.e.drive.providers.SettingsSyncProvider"
android:enabled="true" android:enabled="true"
android:exported="true"/> android:exported="true"
android:label="Application settings" />
<!-- Services --> <!-- Services -->
<service android:name=".services.InitializerService" <service
android:name=".services.InitializerService"
android:enabled="true" android:enabled="true"
android:exported="true"> android:exported="true">
<intent-filter> <intent-filter>
<action android:name="drive.services.InitializerService" /> <action android:name="drive.services.InitializerService" />
</intent-filter> </intent-filter>
</service> </service>
<service android:name=".services.ResetService" <service
android:name=".services.ResetService"
android:enabled="true" android:enabled="true"
android:exported="true"> android:exported="true">
<intent-filter> <intent-filter>
<action android:name="drive.services.ResetService" /> <action android:name="drive.services.ResetService" />
</intent-filter> </intent-filter>
</service> </service>
<service android:name=".jobs.ScannerJob" <service
android:name=".jobs.ScannerJob"
android:permission="android.permission.BIND_JOB_SERVICE" /> android:permission="android.permission.BIND_JOB_SERVICE" />
<service android:name=".services.ObserverService" <service
android:enabled="true"/> android:name=".services.ObserverService"
<service android:name=".services.OperationManagerService"/> android:enabled="true" />
<service android:name=".services.OperationManagerService" />
<!-- Receivers --> <!-- Receivers -->
<receiver android:name=".receivers.BootCompleteReceiver" <receiver
android:name=".receivers.BootCompleteReceiver"
android:enabled="true"> android:enabled="true">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter> </intent-filter>
</receiver> </receiver>
<receiver android:name=".receivers.BatteryStateReceiver" android:enabled="true"> <receiver
android:name=".receivers.BatteryStateReceiver"
android:enabled="true">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.BATTERY_LOW"/> <action android:name="android.intent.action.BATTERY_LOW" />
<action android:name="android.intent.action.BATTERY_OKAY"/> <action android:name="android.intent.action.BATTERY_OKAY" />
</intent-filter> </intent-filter>
</receiver> </receiver>
<receiver android:name=".receivers.PackageEventReceiver" android:enabled="true"> <receiver
android:name=".receivers.PackageEventReceiver"
android:enabled="true">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED"/> <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
</intent-filter> </intent-filter>
</receiver> </receiver>
</application> </application>
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
package foundation.e.drive.receivers; package foundation.e.drive.receivers;
import android.accounts.Account;
import android.accounts.AccountManager; import android.accounts.AccountManager;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
...@@ -15,32 +16,52 @@ import android.content.Intent; ...@@ -15,32 +16,52 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.util.Log; import android.util.Log;
import foundation.e.drive.R;
import foundation.e.drive.utils.AppConstants; import foundation.e.drive.utils.AppConstants;
import foundation.e.drive.utils.CommonUtils;
import foundation.e.drive.utils.JobUtils; import foundation.e.drive.utils.JobUtils;
public class BootCompleteReceiver extends BroadcastReceiver { public class BootCompleteReceiver extends BroadcastReceiver {
private final static String TAG = BootCompleteReceiver.class.getSimpleName(); private final static String TAG = BootCompleteReceiver.class.getSimpleName();
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
Log.i(TAG, "onReceive"); 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"); 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); 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 //If user account is registered
prefs.edit().putBoolean(AppConstants.KEY_OMS_IS_WORKING, false).commit(); 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 //scanner job isn't registered then register it
JobUtils.scheduleScannerJob(context); 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; ...@@ -22,13 +22,17 @@ import android.net.Uri;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.util.Log; import android.util.Log;
import android.webkit.MimeTypeMap; import android.webkit.MimeTypeMap;
import com.owncloud.android.lib.common.OwnCloudBasicCredentials; import com.owncloud.android.lib.common.OwnCloudBasicCredentials;
import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientFactory; import com.owncloud.android.lib.common.OwnCloudClientFactory;
import com.owncloud.android.lib.common.accounts.AccountUtils; import com.owncloud.android.lib.common.accounts.AccountUtils;
import com.owncloud.android.lib.resources.files.FileUtils; import com.owncloud.android.lib.resources.files.FileUtils;
import java.io.File; import java.io.File;
import foundation.e.drive.receivers.ScreenOffReceiver; import foundation.e.drive.receivers.ScreenOffReceiver;
import static foundation.e.drive.utils.AppConstants.MEDIASYNC_PROVIDER_AUTHORITY; import static foundation.e.drive.utils.AppConstants.MEDIASYNC_PROVIDER_AUTHORITY;
import static foundation.e.drive.utils.AppConstants.SETTINGSYNC_PROVIDER_AUTHORITY; import static foundation.e.drive.utils.AppConstants.SETTINGSYNC_PROVIDER_AUTHORITY;
...@@ -37,35 +41,37 @@ import static foundation.e.drive.utils.AppConstants.SETTINGSYNC_PROVIDER_AUTHORI ...@@ -37,35 +41,37 @@ import static foundation.e.drive.utils.AppConstants.SETTINGSYNC_PROVIDER_AUTHORI
* @author Vincent Bourgmayer * @author Vincent Bourgmayer
*/ */
public abstract class CommonUtils { public abstract class CommonUtils {
final private static String TAG = CommonUtils.class.getSimpleName(); final private static String TAG = CommonUtils.class.getSimpleName();
/** /**
* Set ServiceUncaughtExceptionHandler to be the MainThread Exception Handler * Set ServiceUncaughtExceptionHandler to be the MainThread Exception Handler
* Or update the service which use it * Or update the service which use it
*
* @param service current service * @param service current service
*/ */
public static void setServiceUnCaughtExceptionHandler(Service service){ public static void setServiceUnCaughtExceptionHandler(Service service) {
Thread.UncaughtExceptionHandler defaultUEH = Thread.getDefaultUncaughtExceptionHandler(); 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!"); Log.d("ObserverService", "ServiceExceptionHandler already set!");
((ServiceExceptionHandler) defaultUEH).setService(service); ((ServiceExceptionHandler) defaultUEH).setService(service);
}else{ } else {
Thread.setDefaultUncaughtExceptionHandler(new ServiceExceptionHandler(service)); Thread.setDefaultUncaughtExceptionHandler(new ServiceExceptionHandler(service));
} }
} }
/** /**
* Unregister from screeOffReceiver component * Unregister from screeOffReceiver component
*
* @param context app context * @param context app context
* @return true if unregistration was successful or false if it encounter an exception * @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 { try {
Log.d("TAG", "unregisterReceiver(screenOffReceiver)"); Log.d("TAG", "unregisterReceiver(screenOffReceiver)");
context.unregisterReceiver(ScreenOffReceiver.getInstance()); context.unregisterReceiver(ScreenOffReceiver.getInstance());
}catch(IllegalArgumentException e){ } catch (IllegalArgumentException e) {
Log.w(TAG, "Can't unregister screenOffReceiver "); Log.w(TAG, "Can't unregister screenOffReceiver ");
return false; return false;
} }
...@@ -75,47 +81,68 @@ public abstract class CommonUtils { ...@@ -75,47 +81,68 @@ public abstract class CommonUtils {
/** /**
* This method retrieve Account corresponding to account's name and type * This method retrieve Account corresponding to account's name and type
*
* @param accountName Account Name, shouldn't be null * @param accountName Account Name, shouldn't be null
* @param accountType account type * @param accountType account type
* @param am Account Manager * @param am Account Manager
* @return Account or null if not found * @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); Account[] accounts = am.getAccountsByType(accountType);
for(int i = -1, size = accounts.length; ++i < size;){ for (int i = -1, size = accounts.length; ++i < size; ) {
if(accounts[i].name.equals( accountName )){ if (accounts[i].name.equals(accountName)) {
return accounts[i]; return accounts[i];
} }
} }
return null; 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 * Say if synchronisation is allowed
* @param account Account used for synchronisation *
* @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 * @param syncedFileStateIsMedia true if the concerned syncedFileState is a media's type element, false if it is a settings's type element
* @return * @return
*/ */
public static boolean isThisSyncAllowed(Account account, boolean syncedFileStateIsMedia){ public static boolean isThisSyncAllowed(Account account, boolean syncedFileStateIsMedia) {
return ( syncedFileStateIsMedia && isMediaSyncEnabled(account) ) return (syncedFileStateIsMedia && isMediaSyncEnabled(account))
|| ( !syncedFileStateIsMedia && isSettingsSyncEnabled(account) ) ; || (!syncedFileStateIsMedia && isSettingsSyncEnabled(account));
} }
/** /**
* Say if Media Sync is enabled in account * Say if Media Sync is enabled in account
*
* @param account Concerned account * @param account Concerned account
* @return true if media sync enabled * @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); return ContentResolver.getSyncAutomatically(account, MEDIASYNC_PROVIDER_AUTHORITY);
} }
/** /**
* Say if Settings Sync is enabled in account * Say if Settings Sync is enabled in account
*
* @param account Concerned account * @param account Concerned account
* @return true if enabled * @return true if enabled
*/ */
public static boolean isSettingsSyncEnabled(Account account){ public static boolean isSettingsSyncEnabled(Account account) {
return ContentResolver.getSyncAutomatically(account, SETTINGSYNC_PROVIDER_AUTHORITY); return ContentResolver.getSyncAutomatically(account, SETTINGSYNC_PROVIDER_AUTHORITY);
} }
...@@ -130,10 +157,10 @@ public abstract class CommonUtils { ...@@ -130,10 +157,10 @@ public abstract class CommonUtils {
try { try {
serverUri = Uri.parse(AccountUtils.getBaseUrlForAccount(context, account)); serverUri = Uri.parse(AccountUtils.getBaseUrlForAccount(context, account));
oc = OwnCloudClientFactory.createOwnCloudClient(serverUri, context, true); 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){ } catch (Exception e) {
Log.e(TAG, "Can\'t parse serverPath to Uri : "+e.toString() ); Log.e(TAG, "Can\'t parse serverPath to Uri : " + e.toString());
oc = null; oc = null;
} }
return oc; return oc;
...@@ -144,15 +171,16 @@ public abstract class CommonUtils { ...@@ -144,15 +171,16 @@ public abstract class CommonUtils {
/** /**
* Return name of a file from its access path * Return name of a file from its access path
*
* @param path File name will be extracted from this path. Do not provide directory 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 * @return String, the last part after separator of path or null if invalid path has been provided
*/ */
public static String getFileNameFromPath(String path) { public static String getFileNameFromPath(String path) {
try{ try {
String[] splittedString = path.split(FileUtils.PATH_SEPARATOR); String[] splittedString = path.split(FileUtils.PATH_SEPARATOR);
return splittedString[splittedString.length - 1]; return splittedString[splittedString.length - 1];
}catch(Exception e){ } catch (Exception e) {
Log.e(TAG, e.toString() ); Log.e(TAG, e.toString());
return null; return null;
} }
} }
...@@ -207,15 +235,15 @@ public abstract class CommonUtils { ...@@ -207,15 +235,15 @@ public abstract class CommonUtils {
public static void doActionMediaScannerConnexionScanFile(Context context, final String filePath) { public static void doActionMediaScannerConnexionScanFile(Context context, final String filePath) {
Log.i(TAG, "doActionMediaScannerConnexionScanFile(" + filePath + ")"); Log.i(TAG, "doActionMediaScannerConnexionScanFile(" + filePath + ")");
MediaScannerConnection.scanFile(context, MediaScannerConnection.scanFile(context,
new String[]{filePath}, new String[]{filePath},
new String[]{getMimeType(new File(filePath))}, new String[]{getMimeType(new File(filePath))},
new MediaScannerConnection.OnScanCompletedListener() { new MediaScannerConnection.OnScanCompletedListener() {
@Override @Override
public void onScanCompleted(String path, Uri uri) { public void onScanCompleted(String path, Uri uri) {
Log.v("MediaScanWork", "file " + path Log.v("MediaScanWork", "file " + path
+ " was scanned successfully: " + uri); + " was scanned successfully: " + uri);
} }
}); });
} }
/** /**
...@@ -237,22 +265,23 @@ public abstract class CommonUtils { ...@@ -237,22 +265,23 @@ public abstract class CommonUtils {
/** /**
* Used for debug * Used for debug
* @dev-only *
* @param f File to debug * @param f File to debug
* @return String showing value of file's properties * @return String showing value of file's properties
* @dev-only
*/ */
public static String debugFile(File f) { public static String debugFile(File f) {
return "File name: "+f.getName() return "File name: " + f.getName()
+"\n File exist?: "+f.exists() + "\n File exist?: " + f.exists()
+"\n File absolute path: "+f.getAbsolutePath() + "\n File absolute path: " + f.getAbsolutePath()
+"\n File path: "+f.getPath() + "\n File path: " + f.getPath()
+"\n File length: "+f.length() + "\n File length: " + f.length()
+"\n File last modif: "+f.lastModified() + "\n File last modif: " + f.lastModified()
+"\n File readable?: "+f.canRead() + "\n File readable?: " + f.canRead()
+"\n File writable?: "+f.canWrite() + "\n File writable?: " + f.canWrite()
+"\n File is file?: "+f.isFile() + "\n File is file?: " + f.isFile()
+"\n File is Dir?: "+f.isDirectory() + "\n File is Dir?: " + f.isDirectory()
+"\n File can be read?: "+f.canRead() + "\n File can be read?: " + f.canRead()
+"\n File can be written?: "+f.canWrite(); + "\n File can be written?: " + f.canWrite();
} }
} }
\ No newline at end of file
<resources> <resources>
<string name="app_name">/e/ Drive</string> <string name="app_name">/e/ Drive</string>
<string name="eelo_account_type" translatable="false">e.foundation.webdav.eelo</string>
</resources> </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