@Test public void handleMessage_startExecution() throws Exception { Message startExecutionMsg = Message.obtain(); startExecutionMsg.what = GooglePlayMessageHandler.MSG_START_EXEC; Bundle data = new Bundle(); data.putString(REQUEST_PARAM_TAG, "TAG"); startExecutionMsg.setData(data); startExecutionMsg.replyTo = messengerMock; JobInvocation jobInvocation = new Builder() .setTag("tag") .setService(TestJobService.class.getName()) .setTrigger(Trigger.NOW) .build(); when(receiverMock.prepareJob(any(GooglePlayMessengerCallback.class), eq(data))) .thenReturn(jobInvocation); when(contextMock.bindService( any(Intent.class), any(JobServiceConnection.class), eq(BIND_AUTO_CREATE))) .thenReturn(true); handler.handleMessage(startExecutionMsg); verify(contextMock) .bindService(any(Intent.class), jobServiceConnectionCaptor.capture(), eq(BIND_AUTO_CREATE)); assertTrue(jobServiceConnectionCaptor.getValue().hasJobInvocation(jobInvocation)); }
@Override public void handleMessage(Message message) { if (message == null) { return; } AppOpsManager appOpsManager = (AppOpsManager) googlePlayReceiver.getApplicationContext().getSystemService(Context.APP_OPS_SERVICE); try { appOpsManager.checkPackage(message.sendingUid, GooglePlayDriver.BACKEND_PACKAGE); } catch (SecurityException e) { Log.e(TAG, "Message was not sent from GCM."); return; } switch (message.what) { case MSG_START_EXEC: handleStartMessage(message); break; case MSG_STOP_EXEC: handleStopMessage(message); break; case MSG_INIT: break; default: Log.e(TAG, "Unrecognized message received: " + message); break; } }
GooglePlayMessageHandler extends Handler { @Override public void handleMessage(Message message) { if (message == null) { return; } AppOpsManager appOpsManager = (AppOpsManager) googlePlayReceiver.getApplicationContext().getSystemService(Context.APP_OPS_SERVICE); try { appOpsManager.checkPackage(message.sendingUid, GooglePlayDriver.BACKEND_PACKAGE); } catch (SecurityException e) { Log.e(TAG, "Message was not sent from GCM."); return; } switch (message.what) { case MSG_START_EXEC: handleStartMessage(message); break; case MSG_STOP_EXEC: handleStopMessage(message); break; case MSG_INIT: break; default: Log.e(TAG, "Unrecognized message received: " + message); break; } } }
GooglePlayMessageHandler extends Handler { @Override public void handleMessage(Message message) { if (message == null) { return; } AppOpsManager appOpsManager = (AppOpsManager) googlePlayReceiver.getApplicationContext().getSystemService(Context.APP_OPS_SERVICE); try { appOpsManager.checkPackage(message.sendingUid, GooglePlayDriver.BACKEND_PACKAGE); } catch (SecurityException e) { Log.e(TAG, "Message was not sent from GCM."); return; } switch (message.what) { case MSG_START_EXEC: handleStartMessage(message); break; case MSG_STOP_EXEC: handleStopMessage(message); break; case MSG_INIT: break; default: Log.e(TAG, "Unrecognized message received: " + message); break; } } GooglePlayMessageHandler(Looper mainLooper, GooglePlayReceiver googlePlayReceiver); }
GooglePlayMessageHandler extends Handler { @Override public void handleMessage(Message message) { if (message == null) { return; } AppOpsManager appOpsManager = (AppOpsManager) googlePlayReceiver.getApplicationContext().getSystemService(Context.APP_OPS_SERVICE); try { appOpsManager.checkPackage(message.sendingUid, GooglePlayDriver.BACKEND_PACKAGE); } catch (SecurityException e) { Log.e(TAG, "Message was not sent from GCM."); return; } switch (message.what) { case MSG_START_EXEC: handleStartMessage(message); break; case MSG_STOP_EXEC: handleStopMessage(message); break; case MSG_INIT: break; default: Log.e(TAG, "Unrecognized message received: " + message); break; } } GooglePlayMessageHandler(Looper mainLooper, GooglePlayReceiver googlePlayReceiver); @Override void handleMessage(Message message); }
GooglePlayMessageHandler extends Handler { @Override public void handleMessage(Message message) { if (message == null) { return; } AppOpsManager appOpsManager = (AppOpsManager) googlePlayReceiver.getApplicationContext().getSystemService(Context.APP_OPS_SERVICE); try { appOpsManager.checkPackage(message.sendingUid, GooglePlayDriver.BACKEND_PACKAGE); } catch (SecurityException e) { Log.e(TAG, "Message was not sent from GCM."); return; } switch (message.what) { case MSG_START_EXEC: handleStartMessage(message); break; case MSG_STOP_EXEC: handleStopMessage(message); break; case MSG_INIT: break; default: Log.e(TAG, "Unrecognized message received: " + message); break; } } GooglePlayMessageHandler(Looper mainLooper, GooglePlayReceiver googlePlayReceiver); @Override void handleMessage(Message message);  }