@Override public void onStart(@Nullable Intent intent, int startId) { Message msg = mServiceHandler.obtainMessage(); msg.arg1 = startId; msg.obj = intent; mServiceHandler.sendMessage(msg); }
private boolean msgTypeUndockedPermanent(BluetoothDevice device, int startId) { // Grace period passed. Disconnect. handleUndocked(device); if (device != null) { final SharedPreferences prefs = getPrefs(); if (DEBUG) { Log.d( TAG, "DISABLE_BT_WHEN_UNDOCKED = " + prefs.getBoolean(KEY_DISABLE_BT_WHEN_UNDOCKED, false)); } if (prefs.getBoolean(KEY_DISABLE_BT_WHEN_UNDOCKED, false)) { if (hasOtherConnectedDevices(device)) { // Don't disable BT if something is connected prefs.edit().remove(KEY_DISABLE_BT_WHEN_UNDOCKED).apply(); } else { // BT was disabled when we first docked if (DEBUG) { Log.d(TAG, "QUEUED BT DISABLE"); } // Queue a delayed msg to disable BT Message newMsg = mServiceHandler.obtainMessage(MSG_TYPE_DISABLE_BT, 0, startId, null); mServiceHandler.sendMessageDelayed(newMsg, DISABLE_BT_GRACE_PERIOD); return true; } } } return false; }
/** * Entry point to add a new operation to the queue of operations. * * <p>New operations are added calling to startService(), resulting in a call to this method. This * ensures the service will keep on working although the caller activity goes away. */ @Override public int onStartCommand(Intent intent, int flags, int startId) { Log_OC.d(TAG, "Starting command with id " + startId); // WIP: for the moment, only SYNC_FOLDER is expected here; // the rest of the operations are requested through the Binder if (ACTION_SYNC_FOLDER.equals(intent.getAction())) { if (!intent.hasExtra(EXTRA_ACCOUNT) || !intent.hasExtra(EXTRA_REMOTE_PATH)) { Log_OC.e(TAG, "Not enough information provided in intent"); return START_NOT_STICKY; } Account account = intent.getParcelableExtra(EXTRA_ACCOUNT); String remotePath = intent.getStringExtra(EXTRA_REMOTE_PATH); Pair<Account, String> itemSyncKey = new Pair<Account, String>(account, remotePath); Pair<Target, RemoteOperation> itemToQueue = newOperation(intent); if (itemToQueue != null) { mSyncFolderHandler.add( account, remotePath, (SynchronizeFolderOperation) itemToQueue.second); Message msg = mSyncFolderHandler.obtainMessage(); msg.arg1 = startId; msg.obj = itemSyncKey; mSyncFolderHandler.sendMessage(msg); } } else { Message msg = mOperationsHandler.obtainMessage(); msg.arg1 = startId; mOperationsHandler.sendMessage(msg); } return START_NOT_STICKY; }
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.i("ServiceStartArguments", "Starting #" + startId + ": " + intent.getExtras()); Message msg = mServiceHandler.obtainMessage(); msg.arg1 = startId; msg.arg2 = flags; msg.obj = intent.getExtras(); mServiceHandler.sendMessage(msg); Log.i("ServiceStartArguments", "Sending: " + msg); // For the start fail button, we will simulate the process dying // for some reason in onStartCommand(). if (intent.getBooleanExtra("fail", false)) { // Don't do this if we are in a retry... the system will // eventually give up if we keep crashing. if ((flags & START_FLAG_RETRY) == 0) { // Since the process hasn't finished handling the command, // it will be restarted with the command again, regardless of // whether we return START_REDELIVER_INTENT. Process.killProcess(Process.myPid()); } } // Normally we would consistently return one kind of result... // however, here we will select between these two, so you can see // how they impact the behavior. Try killing the process while it // is in the middle of executing the different commands. return intent.getBooleanExtra("redeliver", false) ? START_REDELIVER_INTENT : START_NOT_STICKY; }
/** Send message. */ @Override public int onStartCommand(Intent intent, int flags, int startId) { Log.d(LOG_TAG, "onStartCommand of DarshakService is called."); Message msg = mServiceHandler.obtainMessage(); msg.arg1 = startId; mServiceHandler.sendMessage(msg); return START_STICKY; }
@Override public void onStart(Intent intent, int startId) { mResultCode = intent != null ? intent.getIntExtra("result", 0) : 0; Message msg = mServiceHandler.obtainMessage(); msg.arg1 = startId; msg.obj = intent; mServiceHandler.sendMessage(msg); }
@Override public int onStartCommand(Intent intent, int flags, int startId) { Message msg = mServiceHandler.obtainMessage(); msg.arg1 = startId; msg.what = MSG_UPDATE_AUTO; mServiceHandler.sendMessage(msg); return START_STICKY; }
@Override public void onStart(Intent intent, int startId) { if (Log.DEBUG) Log.v("SMSReceiverService: onStart()"); mResultCode = intent != null ? intent.getIntExtra("result", 0) : 0; Message msg = mServiceHandler.obtainMessage(); msg.arg1 = startId; msg.obj = intent; mServiceHandler.sendMessage(msg); }
public void run() { Looper.prepare(); mServiceHandler = new ServiceHandler(); handlerIsCreated = true; Message msg = mServiceHandler.obtainMessage(); msg.what = OPEN_DATABASE; mServiceHandler.sendMessage(msg); if (needToSaveTransaction) { Message msgSave = mServiceHandler.obtainMessage(); msgSave.what = INSERT_DATA; msgSave.obj = bundle; needToSaveTransaction = false; bundle = null; mServiceHandler.sendMessage(msgSave); } if (callbackObject != null) { callbackObject.onReady(); } Looper.loop(); }
@Override public void onStart(Intent intent, int startId) { Log.v("TTSNotifierService", "onStart()"); if (myTts == null) { try { myTts = new TextToSpeech(context, ttsInitListener); } catch (java.lang.ExceptionInInitializerError e) { e.printStackTrace(); } } if (mPrefs.getBoolean("cbxChangeLanguage", false)) setLanguageTts(myLanguage.getLocale()); Message msg = mServiceHandler.obtainMessage(); msg.arg1 = startId; msg.obj = intent; mServiceHandler.sendMessage(msg); }
@Override public int onStartCommand(Intent intent, int flags, int startId) { // Toast.makeText(this, "service starting", Toast.LENGTH_SHORT).show(); // For each start request, send a message to start a job and deliver the // start ID so we know which request we're stopping when we finish the // job Message msg = mServiceHandler.obtainMessage(); msg.arg1 = startId; mServiceHandler.sendMessage(msg); Log.d(DEBUG_TAG, ">>>onStartCommand()"); sharedPreferences = getSharedPreferences("LOGIN_DETAIL", 0); CLIENT_ID = sharedPreferences.getString("CLIENTID", ""); UpdateCarCurrentLocation(CLIENT_ID); // If we get killed, after returning from here, restart return START_STICKY; }
/** * Entry point to add a new operation to the queue of operations. * * <p>New operations are added calling to startService(), resulting in a call to this method. This * ensures the service will keep on working although the caller activity goes away. * * <p>IMPORTANT: the only operations performed here right now is {@link GetSharedFilesOperation}. * The class is taking advantage of it due to time constraints. */ @Override public int onStartCommand(Intent intent, int flags, int startId) { if (!intent.hasExtra(EXTRA_ACCOUNT) && !intent.hasExtra(EXTRA_SERVER_URL)) { Log_OC.e(TAG, "Not enough information provided in intent"); return START_NOT_STICKY; } try { Account account = intent.getParcelableExtra(EXTRA_ACCOUNT); String serverUrl = intent.getStringExtra(EXTRA_SERVER_URL); Target target = new Target(account, (serverUrl == null) ? null : Uri.parse(serverUrl)); RemoteOperation operation = null; String action = intent.getAction(); if (action.equals(ACTION_CREATE_SHARE)) { // Create Share String remotePath = intent.getStringExtra(EXTRA_REMOTE_PATH); Intent sendIntent = intent.getParcelableExtra(EXTRA_SEND_INTENT); if (remotePath.length() > 0) { operation = new CreateShareOperation( remotePath, ShareType.PUBLIC_LINK, "", false, "", 1, sendIntent); } } else if (action.equals(ACTION_UNSHARE)) { // Unshare file String remotePath = intent.getStringExtra(EXTRA_REMOTE_PATH); if (remotePath.length() > 0) { operation = new UnshareLinkOperation(remotePath, this.getApplicationContext()); } } else { // nothing we are going to handle return START_NOT_STICKY; } mPendingOperations.add(new Pair<Target, RemoteOperation>(target, operation)); // sendBroadcastNewOperation(target, operation); Message msg = mServiceHandler.obtainMessage(); msg.arg1 = startId; mServiceHandler.sendMessage(msg); } catch (IllegalArgumentException e) { Log_OC.e(TAG, "Bad information provided in intent: " + e.getMessage()); return START_NOT_STICKY; } return START_NOT_STICKY; }
private Message parseIntent(Intent intent) { BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); int state = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, -1234); if (DEBUG) { Log.d( TAG, "Action: " + intent.getAction() + " State:" + state + " Device: " + (device == null ? "null" : device.getAliasName())); } int msgType; switch (state) { case Intent.EXTRA_DOCK_STATE_UNDOCKED: msgType = MSG_TYPE_UNDOCKED_TEMPORARY; break; case Intent.EXTRA_DOCK_STATE_DESK: case Intent.EXTRA_DOCK_STATE_HE_DESK: case Intent.EXTRA_DOCK_STATE_CAR: if (device == null) { Log.w(TAG, "device is null"); return null; } /// Fall Through /// case Intent.EXTRA_DOCK_STATE_LE_DESK: if (DockEventReceiver.ACTION_DOCK_SHOW_UI.equals(intent.getAction())) { if (device == null) { Log.w(TAG, "device is null"); return null; } msgType = MSG_TYPE_SHOW_UI; } else { msgType = MSG_TYPE_DOCKED; } break; default: return null; } return mServiceHandler.obtainMessage(msgType, state, 0, device); }
@Override public int onStartCommand(Intent intent, int flags, int startId) { // Intent redelivery PowerManager.WakeLock wl = getLock(this); if (!wl.isHeld()) wl.acquire(); // Get command final Command cmd = (intent == null ? Command.start : (Command) intent.getSerializableExtra(EXTRA_COMMAND)); Log.i(TAG, "Start intent=" + intent + " command=" + cmd + " vpn=" + (vpn != null)); // Queue command Message msg = mServiceHandler.obtainMessage(); msg.arg1 = startId; msg.obj = intent; mServiceHandler.sendMessage(msg); return (cmd == Command.stop ? START_NOT_STICKY : START_STICKY); }
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.d(tag, "onStartCommand"); // Toast.makeText(this, "service starting", Toast.LENGTH_SHORT).show(); // For each start request, send a message to start a job and deliver the // start ID so we know which request we're stopping when we finish the job InsiderrService.indexSleepTimes = 0; InsiderrService.serviceIntent = intent; if (InsiderrService.mStarting) { Log.d(tag, "onStartCommand -- message"); Message msg = mServiceHandler.obtainMessage(); msg.arg1 = startId; mServiceHandler.sendMessage(msg); } InsiderrService.mStarting = false; // If we get killed, after returning from here, restart return START_STICKY; }
@Override public int onStartCommand(Intent intent, int flags, int startId) { while (!mInitialized) { try { Thread.sleep(100); } catch (InterruptedException e) { } } if (intent == null) { return Service.START_NOT_STICKY; } Message msg = mHandler.obtainMessage(); msg.arg1 = startId; msg.obj = intent.getExtras(); mHandler.sendMessage(msg); // Try again later if we are killed before we can finish scanning. return Service.START_REDELIVER_INTENT; }
@Override public int onStartCommand(Intent intent, int flags, int startId) { // Keep awake getLock(this).acquire(); // Handle service restart if (intent == null) { Log.i(TAG, "Restart"); // Get enabled SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); boolean enabled = prefs.getBoolean("enabled", false); // Recreate intent intent = new Intent(this, SinkholeService.class); intent.putExtra(EXTRA_COMMAND, enabled ? Command.start : Command.stop); } Command cmd = (Command) intent.getSerializableExtra(EXTRA_COMMAND); String reason = intent.getStringExtra(EXTRA_REASON); Log.i( TAG, "Start intent=" + intent + " command=" + cmd + " reason=" + reason + " vpn=" + (vpn != null)); // Queue command Message msg = mServiceHandler.obtainMessage(); msg.arg1 = startId; msg.obj = intent; msg.what = MSG_SERVICE_INTENT; mServiceHandler.sendMessage(msg); return START_STICKY; }
@Override public int onStartCommand(Intent intent, int flags, int startId) { // Temporarily removed for this duplicate message track down. mResultCode = intent != null ? intent.getIntExtra("result", 0) : 0; if (mResultCode != 0) { Log.v( TAG, "onStart: #" + startId + " mResultCode: " + mResultCode + " = " + translateResultCode(mResultCode)); } Message msg = mServiceHandler.obtainMessage(); msg.arg1 = startId; msg.obj = intent; mServiceHandler.sendMessage(msg); return Service.START_NOT_STICKY; }
@Override public int onStartCommand(Intent intent, int flags, int startId) { if (intent == null) { stopSelf(); return super.onStartCommand(intent, flags, startId); } String type = intent.getStringExtra(TYPE_KEY); if (type == null) { type = intent.getType(); } if (type == null) { stopSelf(); return super.onStartCommand(intent, flags, startId); } if (type.startsWith("keyboard/key")) { Message msg = mServiceHandler.obtainMessage(); int key = intent.getIntExtra(KeyboardActivity.KEYBOARD_KEY, -1); if (key != -1) { Log.d(TAG, "KeyEvent loaded : " + KeyEvent.keyCodeToString(key)); JSONObject jsonPostObject = new JSONObject(); try { jsonPostObject.put("value", key); jsonPostObject.put("mime", "keyboard/key"); } catch (JSONException e) { e.printStackTrace(); } msg.obj = jsonPostObject; mServiceHandler.sendMessage(msg); } } else if (intent.hasExtra(Intent.EXTRA_TEXT)) { Message msg = mServiceHandler.obtainMessage(); String txt = intent.getStringExtra(Intent.EXTRA_TEXT); if (txt != null) { Log.d(TAG, "Text loaded : " + txt); JSONObject jsonPostObject = new JSONObject(); try { jsonPostObject.put("value", txt); jsonPostObject.put("mime", "text/plain"); } catch (JSONException e) { e.printStackTrace(); } msg.obj = jsonPostObject; mServiceHandler.sendMessage(msg); // BroadcastTask task = new BroadcastTask(getApplicationContext()); // task.execute(BroadcastTask.SEND_TEXT, txt, type); } } else if (intent.hasExtra(Intent.EXTRA_STREAM)) { Uri streamUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM); File file = AndroidUtils.getFile(this, streamUri, false); Log.d(TAG, "Stream loaded : " + file.getPath()); try { if (server != null) { server.stop(); } server = new NanoHTTPDSender(0, null, this); Message msg = mServiceHandler.obtainMessage(); Uri uri = Uri.fromFile(file); Log.d(TAG, "File Uri : " + uri); String filePath = server.addFile(mHttpService, uri); Log.d(TAG, "Server File path : " + filePath); URL ext = new URL(new URL(server.getLocalhost()), filePath); Log.d(TAG, "External URL : " + ext.toExternalForm()); String mimetype = null; String extension = "*"; if (file.getName().contains(".")) { extension = AndroidUtils.extension(file.getName()); mimetype = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); } if (mimetype == null) { if (type.startsWith("*/")) { mimetype = "application/" + extension; } else { mimetype = type.replace("/*", "/" + extension); } } JSONObject jsonPostObject = new JSONObject(); try { jsonPostObject.put("value", ext.toExternalForm()); jsonPostObject.put("mime", mimetype != null ? mimetype : type); jsonPostObject.put("extension", extension); } catch (JSONException e) { e.printStackTrace(); } msg.obj = jsonPostObject; mServiceHandler.sendMessage(msg); } catch (MalformedURLException e) { Log.d(TAG, Log.getStackTraceString(e)); } catch (IOException e) { Log.d(TAG, Log.getStackTraceString(e)); } } return super.onStartCommand(intent, flags, startId); }
/** * Entry point to add one or several files to the queue of uploads. * * <p>New uploads are added calling to startService(), resulting in a call to this method. This * ensures the service will keep on working although the caller activity goes away. */ @Override public int onStartCommand(Intent intent, int flags, int startId) { if (!intent.hasExtra(KEY_ACCOUNT) || !intent.hasExtra(KEY_UPLOAD_TYPE) || !(intent.hasExtra(KEY_LOCAL_FILE) || intent.hasExtra(KEY_FILE))) { Log_OC.e(TAG, "Not enough information provided in intent"); return Service.START_NOT_STICKY; } int uploadType = intent.getIntExtra(KEY_UPLOAD_TYPE, -1); if (uploadType == -1) { Log_OC.e(TAG, "Incorrect upload type provided"); return Service.START_NOT_STICKY; } Account account = intent.getParcelableExtra(KEY_ACCOUNT); String[] localPaths = null, remotePaths = null, mimeTypes = null; OCFile[] files = null; if (uploadType == UPLOAD_SINGLE_FILE) { if (intent.hasExtra(KEY_FILE)) { files = new OCFile[] {intent.getParcelableExtra(KEY_FILE)}; } else { localPaths = new String[] {intent.getStringExtra(KEY_LOCAL_FILE)}; remotePaths = new String[] {intent.getStringExtra(KEY_REMOTE_FILE)}; mimeTypes = new String[] {intent.getStringExtra(KEY_MIME_TYPE)}; } } else { // mUploadType == UPLOAD_MULTIPLE_FILES if (intent.hasExtra(KEY_FILE)) { files = (OCFile[]) intent.getParcelableArrayExtra(KEY_FILE); // TODO // will // this // casting // work // fine? } else { localPaths = intent.getStringArrayExtra(KEY_LOCAL_FILE); remotePaths = intent.getStringArrayExtra(KEY_REMOTE_FILE); mimeTypes = intent.getStringArrayExtra(KEY_MIME_TYPE); } } FileDataStorageManager storageManager = new FileDataStorageManager(account, getContentResolver()); boolean forceOverwrite = intent.getBooleanExtra(KEY_FORCE_OVERWRITE, false); boolean isInstant = intent.getBooleanExtra(KEY_INSTANT_UPLOAD, false); int localAction = intent.getIntExtra(KEY_LOCAL_BEHAVIOUR, LOCAL_BEHAVIOUR_COPY); if (intent.hasExtra(KEY_FILE) && files == null) { Log_OC.e(TAG, "Incorrect array for OCFiles provided in upload intent"); return Service.START_NOT_STICKY; } else if (!intent.hasExtra(KEY_FILE)) { if (localPaths == null) { Log_OC.e(TAG, "Incorrect array for local paths provided in upload intent"); return Service.START_NOT_STICKY; } if (remotePaths == null) { Log_OC.e(TAG, "Incorrect array for remote paths provided in upload intent"); return Service.START_NOT_STICKY; } if (localPaths.length != remotePaths.length) { Log_OC.e(TAG, "Different number of remote paths and local paths!"); return Service.START_NOT_STICKY; } files = new OCFile[localPaths.length]; for (int i = 0; i < localPaths.length; i++) { files[i] = obtainNewOCFileToUpload( remotePaths[i], localPaths[i], ((mimeTypes != null) ? mimeTypes[i] : (String) null), storageManager); if (files[i] == null) { // TODO @andomaex add failure Notification return Service.START_NOT_STICKY; } } } AccountManager aMgr = AccountManager.get(this); String version = aMgr.getUserData(account, OwnCloudAccount.Constants.KEY_OC_VERSION); String versionString = aMgr.getUserData(account, OwnCloudAccount.Constants.KEY_OC_VERSION_STRING); OwnCloudVersion ocv = new OwnCloudVersion(version, versionString); boolean chunked = FileUploader.chunkedUploadIsSupported(ocv); AbstractList<String> requestedUploads = new Vector<String>(); String uploadKey = null; UploadFileOperation newUpload = null; try { for (int i = 0; i < files.length; i++) { uploadKey = buildRemoteName(account, files[i].getRemotePath()); newUpload = new UploadFileOperation( account, files[i], chunked, isInstant, forceOverwrite, localAction, getApplicationContext()); if (isInstant) { newUpload.setRemoteFolderToBeCreated(); } mPendingUploads.putIfAbsent( uploadKey, newUpload); // Grants that the file only upload once time newUpload.addDatatransferProgressListener(this); newUpload.addDatatransferProgressListener((FileUploaderBinder) mBinder); requestedUploads.add(uploadKey); } } catch (IllegalArgumentException e) { Log_OC.e(TAG, "Not enough information provided in intent: " + e.getMessage()); return START_NOT_STICKY; } catch (IllegalStateException e) { Log_OC.e(TAG, "Bad information provided in intent: " + e.getMessage()); return START_NOT_STICKY; } catch (Exception e) { Log_OC.e(TAG, "Unexpected exception while processing upload intent", e); return START_NOT_STICKY; } if (requestedUploads.size() > 0) { Message msg = mServiceHandler.obtainMessage(); msg.arg1 = startId; msg.obj = requestedUploads; mServiceHandler.sendMessage(msg); } Log_OC.i(TAG, "mPendingUploads size:" + mPendingUploads.size()); return Service.START_NOT_STICKY; }
private void msgTypeUndockedTemporary(BluetoothDevice device, int state, int startId) { // Undocked event received. Queue a delayed msg to sever connection Message newMsg = mServiceHandler.obtainMessage(MSG_TYPE_UNDOCKED_PERMANENT, state, startId, device); mServiceHandler.sendMessageDelayed(newMsg, UNDOCKED_GRACE_PERIOD); }