Welcome to mirror list, hosted at ThFree Co, Russian Federation.

GcmInstanceIDRouterListenerService.java « push « util « mapswithme « com « src « android - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c4ab03b4bcfd3f262cc17362ba46ebfed32a770c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.mapswithme.util.push;

import android.support.annotation.Nullable;

import com.google.android.gms.gcm.GoogleCloudMessaging;
import com.google.android.gms.iid.InstanceID;
import com.google.android.gms.iid.InstanceIDListenerService;
import com.mapswithme.util.log.Logger;
import com.mapswithme.util.log.LoggerFactory;
import com.pushwoosh.PushwooshFcmHelper;

import java.io.IOException;

public class GcmInstanceIDRouterListenerService extends InstanceIDListenerService
{
  private static final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.THIRD_PARTY);
  private static final String TAG = GcmInstanceIDRouterListenerService.class.getSimpleName();
  
  @Override
  public void onTokenRefresh()
  {
    LOGGER.i(TAG, "onTokenRefresh()");
    super.onTokenRefresh();
    try
    {
      onTokenRefreshInternal();
    }
    catch (IOException e)
    {
      LOGGER.e(TAG, "Failed to obtained refreshed token: ", e);
    }
  }

  private void onTokenRefreshInternal() throws IOException
  {    
    String token = getRefreshedToken();
    PushwooshFcmHelper.onTokenRefresh(this, token);
  }

  @Nullable
  private String getRefreshedToken() throws IOException
  {
    String projectId = GCMListenerRouterService.getPWProjectId(this);
    InstanceID instanceID = InstanceID.getInstance(getApplicationContext());
    return instanceID.getToken(projectId, GoogleCloudMessaging.INSTANCE_ID_SCOPE);
  }
}