Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
e
os
eDrive
Commits
23e3c3ff
Commit
23e3c3ff
authored
Jul 09, 2020
by
Mohit Mali
Browse files
- Removed sharedUserId
- Fix issue when eDrive doesn't recognise User account after update
parent
f7ba4bd8
Pipeline
#62057
passed with stage
in 2 minutes and 6 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
app/src/main/AndroidManifest.xml
View file @
23e3c3ff
...
...
@@ -7,16 +7,15 @@ 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"
/>
<application
android:allowBackup=
"true"
...
...
@@ -26,55 +25,64 @@ http://www.gnu.org/licenses/gpl.html
<!-- Provider -->
<provider
android:authorities=
"foundation.e.drive.providers.MediasSyncProvider"
android:name=
".providers.MediasSyncProvider"
android:
label=
"Pictures and
vide
os
"
android:
authorities=
"foundation.e.drive.providers.MediasSyncPro
vide
r
"
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>
...
...
app/src/main/java/foundation/e/drive/receivers/BootCompleteReceiver.java
View file @
23e3c3ff
package
foundation.e.drive.receivers
;
import
android.accounts.Account
;
import
android.accounts.AccountManager
;
import
android.content.BroadcastReceiver
;
import
android.content.Context
;
...
...
@@ -7,32 +8,55 @@ 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
){
SharedPreferences
prefs
=
context
.
getSharedPreferences
(
AppConstants
.
SHARED_PREFERENCE_NAME
,
Context
.
MODE_PRIVATE
);
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
);}
JobUtils
.
scheduleScannerJob
(
context
);
}
}
}
}
...
...
app/src/main/java/foundation/e/drive/utils/CommonUtils.java
View file @
23e3c3ff
...
...
@@ -24,13 +24,17 @@ import android.support.annotation.NonNull;
import
android.support.v4.app.NotificationCompat
;
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
;
...
...
@@ -38,54 +42,57 @@ import static foundation.e.drive.utils.AppConstants.SETTINGSYNC_PROVIDER_AUTHORI
/**
* @author Vincent Bourgmayer
*/
public
abstract
class
CommonUtils
{
public
abstract
class
CommonUtils
{
final
private
static
String
TAG
=
CommonUtils
.
class
.
getSimpleName
();
/**
* 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
;
}
return
true
;
}
/**
* Send notification to UI.
*
@dev-only
*
* @param context app context
* @param id notification ID
* @param msg Message of the notification
* @param icon Icon to use
* @param id
notification ID
* @param msg
Message of the notification
* @param icon
Icon to use
* @param pIntent intent to launch when user tap on the notif. Can be null
* @param ticker The ticker message, shown first. Can be null
* @param ticker The ticker message, shown first. Can be null
* @dev-only
*/
public
static
void
sendNotification
(
Context
context
,
int
id
,
String
msg
,
int
icon
,
PendingIntent
pIntent
,
String
ticker
)
{
public
static
void
sendNotification
(
Context
context
,
int
id
,
String
msg
,
int
icon
,
PendingIntent
pIntent
,
String
ticker
)
{
NotificationCompat
.
Builder
builder
=
new
NotificationCompat
.
Builder
(
context
)
.
setSmallIcon
(
icon
)
...
...
@@ -95,23 +102,41 @@ public abstract class CommonUtils {
NotificationManager
notifyMgr
=
(
NotificationManager
)
context
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
);
if
(
pIntent
!=
null
)
builder
.
setContentIntent
(
pIntent
);
if
(
ticker
!=
null
)
builder
.
setTicker
(
ticker
);
if
(
pIntent
!=
null
)
builder
.
setContentIntent
(
pIntent
);
if
(
ticker
!=
null
)
builder
.
setTicker
(
ticker
);
notifyMgr
.
notify
(
id
,
builder
.
build
());
}
/**
* 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
* @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
)
{
Account
[]
accounts
=
am
.
getAccounts
();
for
(
int
i
=
-
1
,
size
=
accounts
.
length
;
++
i
<
size
;
)
{
if
(
accounts
[
i
].
type
.
equals
(
accountType
))
{
return
accounts
[
i
];
}
}
...
...
@@ -121,29 +146,33 @@ public abstract class CommonUtils {
/**
* 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
* @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
);
}
...
...
@@ -151,7 +180,7 @@ public abstract class CommonUtils {
* @param context app context
* @return boolean true if Task could have been launch
*/
public
static
OwnCloudClient
getOwnCloudClient
(
Account
account
,
Context
context
)
{
public
static
OwnCloudClient
getOwnCloudClient
(
Account
account
,
Context
context
)
{
Log
.
i
(
TAG
,
"getOwnCloudClient()"
);
Uri
serverUri
;
...
...
@@ -159,10 +188,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
;
...
...
@@ -172,15 +201,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
;
}
}
...
...
@@ -235,15 +265,15 @@ public abstract class CommonUtils {
public
static
void
doActionMediaScannerConnexionScanFile
(
Context
context
,
final
String
filePath
)
{
Log
.
i
(
TAG
,
"doActionMediaScannerConnexionScanFile("
+
filePath
+
")"
);
MediaScannerConnection
.
scanFile
(
context
,
new
String
[]{
filePath
},
new
String
[]{
getMimeType
(
new
File
(
filePath
))},
new
MediaScannerConnection
.
OnScanCompletedListener
()
{
@Override
public
void
onScanCompleted
(
String
path
,
Uri
uri
)
{
Log
.
v
(
"MediaScanWork"
,
"file "
+
path
+
" was scanned successfully: "
+
uri
);
}
});
new
String
[]{
filePath
},
new
String
[]{
getMimeType
(
new
File
(
filePath
))},
new
MediaScannerConnection
.
OnScanCompletedListener
()
{
@Override
public
void
onScanCompleted
(
String
path
,
Uri
uri
)
{
Log
.
v
(
"MediaScanWork"
,
"file "
+
path
+
" was scanned successfully: "
+
uri
);
}
});
}
/**
...
...
@@ -265,22 +295,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
app/src/main/res/values/strings.xml
View file @
23e3c3ff
<resources>
<string
name=
"app_name"
>
/e/ Drive
</string>
<string
name=
"eelo_account_type"
>
e.foundation.webdav.eelo
</string>
</resources>
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment