Commit 379f84ff authored by narinder Rana's avatar narinder Rana
Browse files

Merge branch 'issue_2401' into 'v1-oreo'

handle null pointer exception

See merge request e/apps/eDrive!42
parents bfa72c8b 53a9b73b
Pipeline #100993 passed with stage
in 6 minutes and 41 seconds
...@@ -239,59 +239,70 @@ public class OperationManagerService extends Service implements OnRemoteOperatio ...@@ -239,59 +239,70 @@ public class OperationManagerService extends Service implements OnRemoteOperatio
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
Log.i(TAG, "onStartCommand()"); Log.i(TAG, "onStartCommand()");
CommonUtils.setServiceUnCaughtExceptionHandler(this); try{
CommonUtils.setServiceUnCaughtExceptionHandler(this);
Bundle extras = intent.getExtras();
Log.d(TAG, "OperationManagerService recieved "+(extras == null ? "null extras": extras.size()+" operations to perform") );
if(extras != null) {
//Load operation from intent
this.mOperationsQueue = new ConcurrentLinkedDeque<>();
for (String key : extras.keySet()) {
Parcelable parcelableObject = extras.getParcelable(key);
if (key.equals("account")) {
this.mAccount = (Account) parcelableObject;
} else if (parcelableObject.getClass().getName().equals(DownloadFileOperation.class.getName())) {
DownloadFileOperation download = (DownloadFileOperation) parcelableObject;
download.setContext(getApplicationContext());
mOperationsQueue.add(download);
} else if (parcelableObject.getClass().getName().equals(UploadFileOperation.class.getName())) {
UploadFileOperation upload = (UploadFileOperation) parcelableObject;
upload.setContext(getApplicationContext());
mOperationsQueue.add(upload);
} else if (parcelableObject.getClass().getName().equals(RemoveFileOperation.class.getName())) {
mOperationsQueue.add((RemoveFileOperation) parcelableObject);
}
}
if(mAccount == null || mOperationsQueue.isEmpty()){ if (null == intent || null == intent.getAction ()) {
Log.w(TAG, "No account or Operation queue is empty"); String source = null == intent ? "intent" : "action";
return super.onStartCommand(intent, flags, startId); Log.e (TAG, source + " was null, flags=" + flags + " bits=" + Integer.toBinaryString (flags));
//return START_STICKY;
} }
//Initialize class's field Bundle extras = intent.getExtras();
this.workerAmount = 4; //This variable could be replace later by an option in settings Log.d(TAG, "OperationManagerService recieved "+(extras == null ? "null extras": extras.size()+" operations to perform") );
this.mThreadPool = new Thread[workerAmount]; if(extras != null) {
this.mThreadWorkingState = new boolean[workerAmount]; //Load operation from intent
this.mHandler = new OperationManagerHandler(this); this.mOperationsQueue = new ConcurrentLinkedDeque<>();
this.mStartedOperations = new Hashtable<RemoteOperation, Integer>(); for (String key : extras.keySet()) {
Parcelable parcelableObject = extras.getParcelable(key);
if (key.equals("account")) {
this.mAccount = (Account) parcelableObject;
} else if (parcelableObject.getClass().getName().equals(DownloadFileOperation.class.getName())) {
DownloadFileOperation download = (DownloadFileOperation) parcelableObject;
download.setContext(getApplicationContext());
mOperationsQueue.add(download);
} else if (parcelableObject.getClass().getName().equals(UploadFileOperation.class.getName())) {
UploadFileOperation upload = (UploadFileOperation) parcelableObject;
upload.setContext(getApplicationContext());
mOperationsQueue.add(upload);
} else if (parcelableObject.getClass().getName().equals(RemoveFileOperation.class.getName())) {
mOperationsQueue.add((RemoveFileOperation) parcelableObject);
}
}
mClient = DavClientProvider.getInstance().getClientInstance(mAccount, getApplicationContext()); if(mAccount == null || mOperationsQueue.isEmpty()){
if (mClient != null) { Log.w(TAG, "No account or Operation queue is empty");
getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE) return super.onStartCommand(intent, flags, startId);
.edit() }
.putBoolean(AppConstants.KEY_OMS_IS_WORKING, true)
.apply();
startAllThreads(); //Initialize class's field
} else { this.workerAmount = 4; //This variable could be replace later by an option in settings
Log.w(TAG, "No Client, Can't Work!");
stopSelf(); this.mThreadPool = new Thread[workerAmount];
this.mThreadWorkingState = new boolean[workerAmount];
this.mHandler = new OperationManagerHandler(this);
this.mStartedOperations = new Hashtable<RemoteOperation, Integer>();
mClient = DavClientProvider.getInstance().getClientInstance(mAccount, getApplicationContext());
if (mClient != null) {
getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE)
.edit()
.putBoolean(AppConstants.KEY_OMS_IS_WORKING, true)
.apply();
startAllThreads();
} else {
Log.w(TAG, "No Client, Can't Work!");
stopSelf();
}
}else{
Log.w(TAG, "Intent's extras is null.");
} }
}else{ }catch (Exception ex){
Log.w(TAG, "Intent's extras is null."); Log.e("Exception", ex.getMessage());
ex.printStackTrace();
} }
return super.onStartCommand(intent, flags, startId); return super.onStartCommand(intent, flags, startId);
......
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