导航菜单

页面标题

页面副标题

Loan Locker v1.5 - ForegroundTokenService.java 源代码

正在查看: Loan Locker v1.5 应用的 ForegroundTokenService.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.user.a4keygen.services;

import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Intent;
import android.os.Build;
import android.os.IBinder;
import android.util.Log;
import androidx.core.app.NotificationCompat;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.messaging.FirebaseMessaging;
import com.google.gson.JsonObject;
import com.user.a4keygen.constants.ServiceKeyValueConstant;
import com.user.a4keygen.constants.WebServiceUrlConstant;
import com.user.a4keygen.model.CommonResponseModel;
import com.user.a4keygen.network.ApiClient;
import com.user.a4keygen.network.ApiInterface;
import com.user.a4keygen.sharedprefrence.SharedPrefManager;
import com.user.a4keygen.util.IconUtils;
import com.user.a4keygen.webutil.WebClientService;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class ForegroundTokenService extends Service {
    private static final String CHANNEL_ID = "ForegroundTokenServiceChannel";
    private static final int NOTIFICATION_ID = 1069;
    private static final String TAG = "FCMToken";

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int i, int i2) {
        createNotificationChannel();
        startForeground(NOTIFICATION_ID, new NotificationCompat.Builder(this, CHANNEL_ID).setContentTitle(WebClientService.getWebServiceUrl().equals(WebServiceUrlConstant.GMM_WEB_SERVICE_URL) ? ServiceKeyValueConstant.TOKEN_UPDATE : "Updating Token").setSmallIcon(IconUtils.getAppIcon()).setPriority(1).build());
        generateFcmToken();
        return 2;
    }

    private void generateFcmToken() {
        Log.d("PrevioseToken", SharedPrefManager.getInstance(getApplicationContext()).getDeviceToken());
        FirebaseMessaging.getInstance().getToken().addOnCompleteListener(new OnCompleteListener<String>() {
            public void onComplete(Task<String> task) {
                if (!task.isSuccessful()) {
                    Log.w("TAG", "Fetching FCM registration token failed", task.getException());
                    return;
                }
                String str = (String) task.getResult();
                Log.d("FCM Token", "Newly generated token: " + str);
                SharedPrefManager.getInstance(ForegroundTokenService.this.getApplicationContext()).saveDeviceToken(str);
                ForegroundTokenService.this.storeToken(str);
            }
        });
    }

    public void storeToken(String str) {
        if (WebClientService.isNull(SharedPrefManager.getInstance(getApplicationContext()).getUserId())) {
            return;
        }
        onSaveTokenOnRemote(str);
    }

    private void onSaveTokenOnRemote(String str) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("id", SharedPrefManager.getInstance(getApplicationContext()).getUserId());
        jsonObject.addProperty("token", str);
        ((ApiInterface) ApiClient.getInstance(this).getClient().create(ApiInterface.class)).tokenUpdate(jsonObject).enqueue(new Callback<CommonResponseModel>() {
            public void onResponse(Call<CommonResponseModel> call, Response<CommonResponseModel> response) {
                if (response.isSuccessful()) {
                    Log.d(ForegroundTokenService.TAG, "Token update success from remote");
                }
            }

            public void onFailure(Call<CommonResponseModel> call, Throwable th) {
                Log.d(ForegroundTokenService.TAG, "Token update failed");
            }
        });
    }

    private void createNotificationChannel() {
        if (Build.VERSION.SDK_INT >= 26) {
            NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID, "Token Service Channel", 3);
            NotificationManager notificationManager = (NotificationManager) getSystemService(NotificationManager.class);
            if (notificationManager != null) {
                notificationManager.createNotificationChannel(notificationChannel);
            }
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        stopForeground(true);
    }
}