android.support.v4.content.WakefulBroadcastReceiver Java Examples

The following examples show how to use android.support.v4.content.WakefulBroadcastReceiver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExternalStatusService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {

    if (intent == null)
        return;

    try {
        final String action = intent.getAction();
        if (action == null) return;

        if (ACTION_NEW_EXTERNAL_STATUSLINE.equals(action)) {
            final String statusLine = intent.getStringExtra(EXTRA_STATUSLINE);
            update(JoH.tsl(), statusLine, true);
        }
    } finally {
        WakefulBroadcastReceiver.completeWakefulIntent(intent);
    }
}
 
Example #2
Source File: ExternalStatusService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {

    if (intent == null)
        return;

    try {
        final String action = intent.getAction();
        if (action == null) return;

        if (ACTION_NEW_EXTERNAL_STATUSLINE.equals(action)) {
            final String statusLine = intent.getStringExtra(EXTRA_STATUSLINE);
            update(JoH.tsl(), statusLine, true);
        }
    } finally {
        WakefulBroadcastReceiver.completeWakefulIntent(intent);
    }
}
 
Example #3
Source File: NotificationIntentService.java    From RememBirthday with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {
    Log.d(getClass().getSimpleName(), "onHandleIntent, started handling a notification event");
    try {
        String action = intent.getAction();
        if (ACTION_START.equals(action)) {
            Contact contact = intent.getParcelableExtra(EXTRA_CONTACT_NOTIFICATION);
            //TODO processStartNotification(contact);
        }
        if (ACTION_DELETE.equals(action)) {
            processDeleteNotification(intent);
        }
    } finally {
        WakefulBroadcastReceiver.completeWakefulIntent(intent);
    }
}
 
Example #4
Source File: InstanceIDListenerService.java    From android_external_GmsLib with Apache License 2.0 6 votes vote down vote up
public int onStartCommand(Intent intent, int flags, int startId) {
    synchronized (this) {
        this.counter++;
        if (startId > this.startId) this.startId = startId;
    }
    try {
        if (intent != null) {
            if (ACTION_INSTANCE_ID.equals(intent.getAction()) && intent.hasExtra(EXTRA_GSF_INTENT)) {
                startService((Intent) intent.getParcelableExtra(EXTRA_GSF_INTENT));
                return START_STICKY;
            }

            handleIntent(intent);

            if (intent.hasExtra(EXTRA_FROM))
                WakefulBroadcastReceiver.completeWakefulIntent(intent);
        }
    } finally {
        stop();
    }
    return START_NOT_STICKY;
}
 
Example #5
Source File: CheckinService.java    From android_packages_apps_GmsCore with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("MissingPermission")
@Override
protected void onHandleIntent(Intent intent) {
    try {
        ForegroundServiceContext.completeForegroundService(this, intent, TAG);
        if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(PREF_ENABLE_CHECKIN, false)) {
            LastCheckinInfo info = CheckinManager.checkin(this, intent.getBooleanExtra(EXTRA_FORCE_CHECKIN, false));
            if (info != null) {
                Log.d(TAG, "Checked in as " + Long.toHexString(info.androidId));
                String accountType = AuthConstants.DEFAULT_ACCOUNT_TYPE;
                for (Account account : AccountManager.get(this).getAccountsByType(accountType)) {
                    PeopleManager.loadUserInfo(this, account);
                }
                McsService.scheduleReconnect(this);
                if (intent.hasExtra(EXTRA_CALLBACK_INTENT)) {
                    startService((Intent) intent.getParcelableExtra(EXTRA_CALLBACK_INTENT));
                }
            }
        }
    } catch (Exception e) {
        Log.w(TAG, e);
    } finally {
        WakefulBroadcastReceiver.completeWakefulIntent(intent);
        stopSelf();
    }
}
 
Example #6
Source File: McsService.java    From android_packages_apps_GmsCore with Apache License 2.0 6 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    ForegroundServiceContext.completeForegroundService(this, intent, TAG);
    synchronized (McsService.class) {
        if (rootHandler != null) {
            if (intent == null) return START_REDELIVER_INTENT;
            wakeLock.acquire(WAKELOCK_TIMEOUT);
            Object reason = intent.hasExtra(EXTRA_REASON) ? intent.getExtras().get(EXTRA_REASON) : intent;
            if (ACTION_CONNECT.equals(intent.getAction())) {
                rootHandler.sendMessage(rootHandler.obtainMessage(MSG_CONNECT, reason));
            } else if (ACTION_HEARTBEAT.equals(intent.getAction())) {
                rootHandler.sendMessage(rootHandler.obtainMessage(MSG_HEARTBEAT, reason));
            } else if (ACTION_SEND.equals(intent.getAction())) {
                handleSendMessage(intent);
            }
            WakefulBroadcastReceiver.completeWakefulIntent(intent);
        } else if (connectIntent == null) {
            connectIntent = intent;
        } else {
            WakefulBroadcastReceiver.completeWakefulIntent(intent);
        }
    }
    return START_REDELIVER_INTENT;
}
 
Example #7
Source File: ExternalStatusService.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {

    if (intent == null)
        return;

    final String action = intent.getAction();

    try {

        if (ACTION_NEW_EXTERNAL_STATUSLINE.equals(action)) {
            String statusline = intent.getStringExtra(EXTRA_STATUSLINE);

            if(statusline.length() > MAX_LEN){
                statusline = statusline.substring(0, MAX_LEN);
            }

            if(statusline != null) {
                // send to wear
                if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("wear_sync", false)) {
                    startService(new Intent(this, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_SEND_STATUS).putExtra("externalStatusString", statusline));
                    /*By integrating the watch part of Nightwatch we inherited the same wakelock
                     problems NW had - so adding the same quick fix for now.
                     TODO: properly "wakelock" the wear (and probably pebble) services
                    */
                    PowerManager powerManager = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
                    powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
                            "quickFix4").acquire(15000);
                }
            }
        }
    } finally {
        WakefulBroadcastReceiver.completeWakefulIntent(intent);
    }
}
 
Example #8
Source File: IntentService.java    From NightWatch with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {
    if (intent == null)
        return;

    final String action = intent.getAction();

    try {
        if (ACTION_NEW_DATA.equals(action)) {
            final double bgEstimate = intent.getDoubleExtra(Intents.EXTRA_BG_ESTIMATE, 0);
            if (bgEstimate == 0)
                return;

            int battery = intent.getIntExtra(Intents.EXTRA_SENSOR_BATTERY, 0);

            final Bg bg = new Bg();
            bg.direction = intent.getStringExtra(Intents.EXTRA_BG_SLOPE_NAME);
            bg.battery = Integer.toString(battery);
            bg.bgdelta = (intent.getDoubleExtra(Intents.EXTRA_BG_SLOPE, 0) * 1000 * 60 * 5);
            bg.datetime = intent.getLongExtra(Intents.EXTRA_TIMESTAMP, new Date().getTime());
            //bg.sgv = Integer.toString((int) bgEstimate, 10);
            bg.sgv = Math.round(bgEstimate)+"";
            bg.raw = intent.getDoubleExtra(Intents.EXTRA_RAW, 0);
            bg.save();

            DataCollectionService.newDataArrived(this, true, bg);
        }
    } finally {
        WakefulBroadcastReceiver.completeWakefulIntent(intent);
    }
}
 
Example #9
Source File: PushReceiver.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
    Bundle extras = intent.getExtras();
    String messageType = gcm.getMessageType(intent);
    if (!extras.isEmpty()) {
        if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            ActorSDK.sharedActor().waitForReady();
            if (extras.containsKey("seq")) {
                int seq = Integer.parseInt(extras.getString("seq"));
                int authId = Integer.parseInt(extras.getString("authId", "0"));
                Log.d(TAG, "Push received #" + seq);
                ActorSDK.sharedActor().getMessenger().onPushReceived(seq, authId);
                setResultCode(Activity.RESULT_OK);
            } else if (extras.containsKey("callId")) {
                long callId = Long.parseLong(extras.getString("callId"));
                int attempt = 0;
                if (extras.containsKey("attemptIndex")) {
                    attempt = Integer.parseInt(extras.getString("attemptIndex"));
                }
                Log.d(TAG, "Received Call #" + callId + " (" + attempt + ")");
                ActorSDK.sharedActor().getMessenger().checkCall(callId, attempt);
                setResultCode(Activity.RESULT_OK);
            }
        }
    }
    WakefulBroadcastReceiver.completeWakefulIntent(intent);
}
 
Example #10
Source File: ReplicationService.java    From sync-android with Apache License 2.0 5 votes vote down vote up
protected void releaseWakeLock(Intent intent) {
    if (intent != null) {
        // Release the WakeLock if there is one. Calling completeWakefulIntent is safe even if
        // there is no wakelock held.
        WakefulBroadcastReceiver.completeWakefulIntent(intent);
    }
}
 
Example #11
Source File: IntentService.java    From NightWatch with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {
    if (intent == null)
        return;

    final String action = intent.getAction();

    try {
        if (ACTION_NEW_DATA.equals(action)) {
            final double bgEstimate = intent.getDoubleExtra(Intents.EXTRA_BG_ESTIMATE, 0);
            if (bgEstimate == 0)
                return;

            int battery = intent.getIntExtra(Intents.EXTRA_SENSOR_BATTERY, 0);

            final Bg bg = new Bg();
            bg.direction = intent.getStringExtra(Intents.EXTRA_BG_SLOPE_NAME);
            bg.battery = Integer.toString(battery);
            bg.bgdelta = (intent.getDoubleExtra(Intents.EXTRA_BG_SLOPE, 0) * 1000 * 60 * 5);
            bg.datetime = intent.getLongExtra(Intents.EXTRA_TIMESTAMP, new Date().getTime());
            //bg.sgv = Integer.toString((int) bgEstimate, 10);
            bg.sgv = Math.round(bgEstimate)+"";
            bg.raw = intent.getDoubleExtra(Intents.EXTRA_RAW, 0);
            bg.save();

            DataCollectionService.newDataArrived(this, true, bg);
        }
    } finally {
        WakefulBroadcastReceiver.completeWakefulIntent(intent);
    }
}
 
Example #12
Source File: JobServiceCompat.java    From JobSchedulerCompat with Apache License 2.0 5 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {
    int msg = intent.getIntExtra(EXTRA_MSG, -1);
    switch (msg) {
        case MSG_SCHEDULE_JOB: {
            JobInfo job = intent.getParcelableExtra(EXTRA_JOB);
            handleSchedule(job);
            break;
        }
        case MSG_CANCEL_JOB: {
            int jobId = intent.getIntExtra(EXTRA_JOB_ID, 0);
            handleCancelJob(jobId);
            break;
        }
        case MSG_CANCEL_ALL: {
            handleCancelAll();
            break;
        }
        case MSG_RUN_JOBS: {
            handleRunJobs();
            boolean releaseWakeLock = intent.getBooleanExtra(EXTRA_RELEASE_WAKE_LOCK, false);
            if (releaseWakeLock) {
                WakefulBroadcastReceiver.completeWakefulIntent(intent);
            }
            break;
        }
        case MSG_BOOT: {
            handleBoot();
        }
        case MSG_JOBS_FINISHED: {
            handleJobsFinished();
        }
    }
}
 
Example #13
Source File: McsService.java    From android_packages_apps_GmsCore with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    Looper.prepare();
    wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "mcs");
    wakeLock.setReferenceCounted(false);
    synchronized (McsService.class) {
        rootHandler = new Handler(Looper.myLooper(), McsService.this);
        if (connectIntent != null) {
            rootHandler.sendMessage(rootHandler.obtainMessage(MSG_CONNECT, connectIntent));
            WakefulBroadcastReceiver.completeWakefulIntent(connectIntent);
        }
    }
    Looper.loop();
}
 
Example #14
Source File: PushRegisterService.java    From android_packages_apps_GmsCore with Apache License 2.0 5 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {
    WakefulBroadcastReceiver.completeWakefulIntent(intent);
    Log.d(TAG, "onHandleIntent: " + intent);

    String requestId = null;
    if (intent.hasExtra(EXTRA_KID) && intent.getStringExtra(EXTRA_KID).startsWith("|")) {
        String[] kid = intent.getStringExtra(EXTRA_KID).split("\\|");
        if (kid.length >= 3 && "ID".equals(kid[1])) {
            requestId = kid[2];
        }
    }

    if (LastCheckinInfo.read(this).lastCheckin > 0) {
        try {
            if (ACTION_C2DM_UNREGISTER.equals(intent.getAction()) ||
                    (ACTION_C2DM_REGISTER.equals(intent.getAction()) && "1".equals(intent.getStringExtra(EXTRA_DELETE)))) {
                unregister(intent, requestId);
            } else if (ACTION_C2DM_REGISTER.equals(intent.getAction())) {
                register(intent, requestId);
            }
        } catch (Exception e) {
            Log.w(TAG, e);
        }
    } else if (!intent.getBooleanExtra(EXTRA_SKIP_TRY_CHECKIN, false)) {
        Log.d(TAG, "No checkin yet, trying to checkin");
        intent.putExtra(EXTRA_SKIP_TRY_CHECKIN, true);
        Intent subIntent = new Intent(this, CheckinService.class);
        subIntent.putExtra(CheckinService.EXTRA_FORCE_CHECKIN, true);
        subIntent.putExtra(CheckinService.EXTRA_CALLBACK_INTENT, intent);
        startService(subIntent);
    }
}
 
Example #15
Source File: GcmRegistrationService.java    From easygcm with Apache License 2.0 5 votes vote down vote up
private void releaseWakeLock() {
    if (mIntent.getBooleanExtra(EXTRA_HAS_WAKELOCK, false)) {
        Intent intent = mIntent;
        mIntent = null;
        WakefulBroadcastReceiver.completeWakefulIntent(intent);
    } else {
        mIntent = null;
    }
}