Commit 9afdf4f0 authored by narinder Rana's avatar narinder Rana
Browse files

handle null pointer exception

parent bfa72c8b
Pipeline #99361 passed with stage
in 2 minutes and 38 seconds
...@@ -239,59 +239,64 @@ public class OperationManagerService extends Service implements OnRemoteOperatio ...@@ -239,59 +239,64 @@ 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") ); 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 if(extras != null) {
this.mOperationsQueue = new ConcurrentLinkedDeque<>(); //Load operation from intent
for (String key : extras.keySet()) { this.mOperationsQueue = new ConcurrentLinkedDeque<>();
for (String key : extras.keySet()) {
Parcelable parcelableObject = extras.getParcelable(key);
if (key.equals("account")) { Parcelable parcelableObject = extras.getParcelable(key);
this.mAccount = (Account) parcelableObject; if (key.equals("account")) {
} else if (parcelableObject.getClass().getName().equals(DownloadFileOperation.class.getName())) { this.mAccount = (Account) parcelableObject;
DownloadFileOperation download = (DownloadFileOperation) parcelableObject; } else if (parcelableObject.getClass().getName().equals(DownloadFileOperation.class.getName())) {
download.setContext(getApplicationContext()); DownloadFileOperation download = (DownloadFileOperation) parcelableObject;
mOperationsQueue.add(download); download.setContext(getApplicationContext());
} else if (parcelableObject.getClass().getName().equals(UploadFileOperation.class.getName())) { mOperationsQueue.add(download);
UploadFileOperation upload = (UploadFileOperation) parcelableObject; } else if (parcelableObject.getClass().getName().equals(UploadFileOperation.class.getName())) {
upload.setContext(getApplicationContext()); UploadFileOperation upload = (UploadFileOperation) parcelableObject;
mOperationsQueue.add(upload); upload.setContext(getApplicationContext());
} else if (parcelableObject.getClass().getName().equals(RemoveFileOperation.class.getName())) { mOperationsQueue.add(upload);
mOperationsQueue.add((RemoveFileOperation) parcelableObject); } else if (parcelableObject.getClass().getName().equals(RemoveFileOperation.class.getName())) {
mOperationsQueue.add((RemoveFileOperation) parcelableObject);
}
} }
}
if(mAccount == null || mOperationsQueue.isEmpty()){
Log.w(TAG, "No account or Operation queue is empty");
return super.onStartCommand(intent, flags, startId);
}
//Initialize class's field
this.workerAmount = 4; //This variable could be replace later by an option in settings
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(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