mirror of https://github.com/NekoX-Dev/NekoX.git
Separate gcm for f-droid build
This commit is contained in:
parent
e20cc7426a
commit
b033b6d704
|
@ -77,7 +77,7 @@ dependencies {
|
|||
|
||||
implementation 'com.google.code.gson:gson:2.8.6'
|
||||
implementation 'org.osmdroid:osmdroid-android:6.1.10'
|
||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.30'
|
||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.31'
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.2'
|
||||
|
||||
implementation "com.squareup.okhttp3:okhttp:$okHttpVersion"
|
||||
|
@ -285,25 +285,45 @@ android {
|
|||
sourceSets {
|
||||
|
||||
main {
|
||||
jni.srcDirs = []
|
||||
jni {
|
||||
srcDirs = []
|
||||
}
|
||||
}
|
||||
|
||||
debug {
|
||||
jniLibs.srcDir 'src/main/libs'
|
||||
manifest.srcFile 'src/gservcies/AndroidManifest.xml'
|
||||
java {
|
||||
srcDirs 'src/main/java', 'src/gservcies/java'
|
||||
}
|
||||
jniLibs {
|
||||
srcDir 'src/main/libs'
|
||||
}
|
||||
manifest {
|
||||
srcFile 'src/gservcies/AndroidManifest.xml'
|
||||
}
|
||||
}
|
||||
|
||||
releaseNoGcm {
|
||||
jniLibs.srcDir 'src/main/libs'
|
||||
jniLibs {
|
||||
srcDir 'src/main/libs'
|
||||
}
|
||||
}
|
||||
|
||||
release {
|
||||
jniLibs.srcDir 'src/main/libs'
|
||||
manifest.srcFile 'src/gservcies/AndroidManifest.xml'
|
||||
java {
|
||||
srcDirs 'src/main/java', 'src/gservcies/java'
|
||||
}
|
||||
jniLibs {
|
||||
srcDir 'src/main/libs'
|
||||
}
|
||||
manifest {
|
||||
srcFile 'src/gservcies/AndroidManifest.xml'
|
||||
}
|
||||
}
|
||||
|
||||
fossRelease {
|
||||
jni.srcDirs = ['./jni/']
|
||||
jni {
|
||||
srcDirs = ['./jni/']
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,135 @@
|
|||
package tw.nekomimi.nekogram;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.IntentSender;
|
||||
import android.text.TextUtils;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
|
||||
import com.google.android.gms.common.ConnectionResult;
|
||||
import com.google.android.gms.common.GoogleApiAvailability;
|
||||
import com.google.android.play.core.appupdate.AppUpdateManager;
|
||||
import com.google.android.play.core.appupdate.AppUpdateManagerFactory;
|
||||
import com.google.android.play.core.install.InstallStateUpdatedListener;
|
||||
import com.google.android.play.core.install.model.AppUpdateType;
|
||||
import com.google.android.play.core.install.model.InstallStatus;
|
||||
import com.google.android.play.core.install.model.UpdateAvailability;
|
||||
import com.google.firebase.iid.FirebaseInstanceId;
|
||||
|
||||
import org.telegram.messenger.ApplicationLoader;
|
||||
import org.telegram.messenger.BuildConfig;
|
||||
import org.telegram.messenger.BuildVars;
|
||||
import org.telegram.messenger.FileLog;
|
||||
import org.telegram.messenger.GcmPushListenerService;
|
||||
import org.telegram.messenger.LocaleController;
|
||||
import org.telegram.messenger.R;
|
||||
import org.telegram.messenger.SharedConfig;
|
||||
import org.telegram.messenger.Utilities;
|
||||
import org.telegram.tgnet.ConnectionsManager;
|
||||
|
||||
import kotlin.Unit;
|
||||
import tw.nekomimi.nekogram.utils.UIUtil;
|
||||
|
||||
@Keep
|
||||
public class GcmImpl implements ExternalGcm.Interface {
|
||||
|
||||
private static Boolean hasPlayServices;
|
||||
|
||||
@Override
|
||||
public boolean checkPlayServices() {
|
||||
if (hasPlayServices != null) return hasPlayServices;
|
||||
try {
|
||||
int resultCode = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(ApplicationLoader.applicationContext);
|
||||
hasPlayServices = resultCode == ConnectionResult.SUCCESS;
|
||||
} catch (Exception e) {
|
||||
hasPlayServices = false;
|
||||
FileLog.e(e);
|
||||
}
|
||||
return hasPlayServices;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initPlayServices() {
|
||||
UIUtil.runOnIoDispatcher(() -> {
|
||||
if (hasPlayServices = checkPlayServices()) {
|
||||
final String currentPushString = SharedConfig.pushString;
|
||||
if (!TextUtils.isEmpty(currentPushString)) {
|
||||
if (BuildVars.DEBUG_PRIVATE_VERSION && BuildVars.LOGS_ENABLED) {
|
||||
FileLog.d("GCM regId = " + currentPushString);
|
||||
}
|
||||
} else {
|
||||
if (BuildVars.LOGS_ENABLED) {
|
||||
FileLog.d("GCM Registration not found.");
|
||||
}
|
||||
}
|
||||
Utilities.globalQueue.postRunnable(() -> {
|
||||
try {
|
||||
FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener(instanceIdResult -> {
|
||||
String token = instanceIdResult.getToken();
|
||||
if (!TextUtils.isEmpty(token)) {
|
||||
GcmPushListenerService.sendRegistrationToServer(token);
|
||||
}
|
||||
}).addOnFailureListener(e -> {
|
||||
if (BuildVars.LOGS_ENABLED) {
|
||||
FileLog.d("Failed to get regid");
|
||||
}
|
||||
SharedConfig.pushStringStatus = "__FIREBASE_FAILED__";
|
||||
GcmPushListenerService.sendRegistrationToServer(null);
|
||||
});
|
||||
} catch (Throwable e) {
|
||||
FileLog.e(e);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (BuildVars.LOGS_ENABLED) {
|
||||
FileLog.d("No valid Google Play Services APK found.");
|
||||
}
|
||||
SharedConfig.pushStringStatus = "__NO_GOOGLE_PLAY_SERVICES__";
|
||||
ConnectionsManager.setRegId(null, SharedConfig.pushStringStatus);
|
||||
}
|
||||
}, 2300);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendRegistrationToServer() {
|
||||
if (!checkPlayServices()) return;
|
||||
GcmPushListenerService.sendRegistrationToServer(SharedConfig.pushString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkUpdate(Activity ctx) {
|
||||
if (!checkPlayServices()) return;
|
||||
AppUpdateManager manager = AppUpdateManagerFactory.create(ctx);
|
||||
InstallStateUpdatedListener listener = (installState) -> {
|
||||
if (installState.installStatus() == InstallStatus.DOWNLOADED) {
|
||||
BottomBuilder builder = new BottomBuilder(ctx);
|
||||
builder.addTitle(LocaleController.getString("UpdateDownloaded", R.string.UpdateDownloaded));
|
||||
builder.addItem(LocaleController.getString("UpdateUpdate", R.string.UpdateUpdate), R.drawable.baseline_system_update_24, false, (it) -> {
|
||||
manager.completeUpdate();
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
builder.addItem(LocaleController.getString("UpdateLater", R.string.UpdateLater), R.drawable.baseline_watch_later_24, false, null);
|
||||
try {
|
||||
builder.show();
|
||||
} catch (WindowManager.BadTokenException e) {
|
||||
manager.completeUpdate();
|
||||
}
|
||||
}
|
||||
};
|
||||
manager.registerListener(listener);
|
||||
manager.getAppUpdateInfo().addOnSuccessListener((appUpdateInfo) -> {
|
||||
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE && appUpdateInfo.availableVersionCode() <= BuildConfig.VERSION_CODE) {
|
||||
FileLog.d("update available");
|
||||
try {
|
||||
manager.startUpdateFlowForResult(appUpdateInfo, AppUpdateType.FLEXIBLE, ctx, 114514);
|
||||
} catch (IntentSender.SendIntentException ignored) {
|
||||
}
|
||||
} else {
|
||||
FileLog.d("no updates");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -175,12 +175,10 @@ import cn.hutool.core.util.StrUtil;
|
|||
import kotlin.Unit;
|
||||
import libv2ray.Libv2ray;
|
||||
import tw.nekomimi.nekogram.BottomBuilder;
|
||||
import tw.nekomimi.nekogram.ExternalGcm;
|
||||
import tw.nekomimi.nekogram.NekoConfig;
|
||||
import tw.nekomimi.nekogram.NekoXConfig;
|
||||
import tw.nekomimi.nekogram.NekoXSettingActivity;
|
||||
import tw.nekomimi.nekogram.parts.DialogTransKt;
|
||||
import tw.nekomimi.nekogram.parts.UpdateChecksKt;
|
||||
import tw.nekomimi.nekogram.settings.NekoSettingsActivity;
|
||||
import tw.nekomimi.nekogram.utils.AlertUtil;
|
||||
import tw.nekomimi.nekogram.utils.EnvUtil;
|
||||
|
@ -2908,12 +2906,6 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
|
|||
updateListAnimated(false);
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
if (ExternalGcm.checkPlayServices()) {
|
||||
builder.addItem(LocaleController.getString("CheckUpdate", R.string.CheckUpdate), R.drawable.baseline_system_update_24, (it) -> {
|
||||
UpdateChecksKt.checkUpdate(ProfileActivity.this.getParentActivity());
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
}
|
||||
builder.addItem(LocaleController.getString("SwitchVersion", R.string.SwitchVersion), R.drawable.baseline_replay_24, (it) -> {
|
||||
Browser.openUrl(ProfileActivity.this.getParentActivity(), "https://github.com/NekoX-Dev/NekoX/releases");
|
||||
return Unit.INSTANCE;
|
||||
|
|
|
@ -1,168 +1,71 @@
|
|||
package tw.nekomimi.nekogram;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.IntentSender;
|
||||
import android.text.TextUtils;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.google.android.gms.common.ConnectionResult;
|
||||
import com.google.android.gms.common.GoogleApiAvailability;
|
||||
import com.google.android.play.core.appupdate.AppUpdateManager;
|
||||
import com.google.android.play.core.appupdate.AppUpdateManagerFactory;
|
||||
import com.google.android.play.core.install.InstallStateUpdatedListener;
|
||||
import com.google.android.play.core.install.model.AppUpdateType;
|
||||
import com.google.android.play.core.install.model.InstallStatus;
|
||||
import com.google.android.play.core.install.model.UpdateAvailability;
|
||||
import com.google.firebase.crashlytics.FirebaseCrashlytics;
|
||||
import com.google.firebase.iid.FirebaseInstanceId;
|
||||
|
||||
import org.h2.util.IOUtils;
|
||||
import org.telegram.messenger.AndroidUtilities;
|
||||
import org.telegram.messenger.ApplicationLoader;
|
||||
import org.telegram.messenger.BuildConfig;
|
||||
import org.telegram.messenger.BuildVars;
|
||||
import org.telegram.messenger.FileLog;
|
||||
import org.telegram.messenger.GcmPushListenerService;
|
||||
import org.telegram.messenger.LocaleController;
|
||||
import org.telegram.messenger.R;
|
||||
import org.telegram.messenger.SharedConfig;
|
||||
import org.telegram.messenger.Utilities;
|
||||
import org.telegram.tgnet.ConnectionsManager;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import kotlin.Unit;
|
||||
import tw.nekomimi.nekogram.utils.UIUtil;
|
||||
|
||||
public class ExternalGcm {
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
private static boolean noGcm = BuildConfig.BUILD_TYPE.contains("NoGcm") || BuildConfig.BUILD_TYPE.contains("Foss");
|
||||
interface Interface {
|
||||
boolean checkPlayServices();
|
||||
|
||||
private static Boolean hasPlayServices;
|
||||
void initPlayServices();
|
||||
|
||||
void sendRegistrationToServer();
|
||||
|
||||
void checkUpdate(Activity ctx);
|
||||
}
|
||||
|
||||
static class NoImpl implements Interface {
|
||||
|
||||
@Override
|
||||
public boolean checkPlayServices() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initPlayServices() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendRegistrationToServer() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkUpdate(Activity ctx) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static Interface impl;
|
||||
|
||||
static {
|
||||
try {
|
||||
impl = (Interface) Class.forName("tw.nekomimi.nekogram.GcmImpl").newInstance();
|
||||
} catch (ClassNotFoundException e) {
|
||||
impl = new NoImpl();
|
||||
} catch (Exception e) {
|
||||
impl = new NoImpl();
|
||||
FileLog.e(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void initPlayServices() {
|
||||
|
||||
UIUtil.runOnIoDispatcher(() -> {
|
||||
if (hasPlayServices = checkPlayServices()) {
|
||||
final String currentPushString = SharedConfig.pushString;
|
||||
if (!TextUtils.isEmpty(currentPushString)) {
|
||||
if (BuildVars.DEBUG_PRIVATE_VERSION && BuildVars.LOGS_ENABLED) {
|
||||
FileLog.d("GCM regId = " + currentPushString);
|
||||
}
|
||||
} else {
|
||||
if (BuildVars.LOGS_ENABLED) {
|
||||
FileLog.d("GCM Registration not found.");
|
||||
}
|
||||
}
|
||||
Utilities.globalQueue.postRunnable(() -> {
|
||||
try {
|
||||
FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener(instanceIdResult -> {
|
||||
String token = instanceIdResult.getToken();
|
||||
if (!TextUtils.isEmpty(token)) {
|
||||
GcmPushListenerService.sendRegistrationToServer(token);
|
||||
}
|
||||
}).addOnFailureListener(e -> {
|
||||
if (BuildVars.LOGS_ENABLED) {
|
||||
FileLog.d("Failed to get regid");
|
||||
}
|
||||
SharedConfig.pushStringStatus = "__FIREBASE_FAILED__";
|
||||
GcmPushListenerService.sendRegistrationToServer(null);
|
||||
});
|
||||
} catch (Throwable e) {
|
||||
FileLog.e(e);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (BuildVars.LOGS_ENABLED) {
|
||||
FileLog.d("No valid Google Play Services APK found.");
|
||||
}
|
||||
SharedConfig.pushStringStatus = "__NO_GOOGLE_PLAY_SERVICES__";
|
||||
ConnectionsManager.setRegId(null, SharedConfig.pushStringStatus);
|
||||
}
|
||||
}, 2300);
|
||||
|
||||
impl.initPlayServices();
|
||||
;
|
||||
}
|
||||
|
||||
public static boolean checkPlayServices() {
|
||||
if (noGcm) return false;
|
||||
if (hasPlayServices != null) return hasPlayServices;
|
||||
try {
|
||||
int resultCode = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(ApplicationLoader.applicationContext);
|
||||
hasPlayServices = resultCode == ConnectionResult.SUCCESS;
|
||||
} catch (Exception e) {
|
||||
hasPlayServices = false;
|
||||
FileLog.e(e);
|
||||
}
|
||||
return hasPlayServices;
|
||||
return impl.checkPlayServices();
|
||||
}
|
||||
|
||||
public static void sendRegistrationToServer() {
|
||||
if (!checkPlayServices()) return;
|
||||
GcmPushListenerService.sendRegistrationToServer(SharedConfig.pushString);
|
||||
impl.sendRegistrationToServer();
|
||||
}
|
||||
|
||||
|
||||
public static void checkUpdate(Activity ctx) {
|
||||
if (!checkPlayServices()) return;
|
||||
|
||||
AppUpdateManager manager = AppUpdateManagerFactory.create(ctx);
|
||||
|
||||
InstallStateUpdatedListener listener = (installState) -> {
|
||||
|
||||
if (installState.installStatus() == InstallStatus.DOWNLOADED) {
|
||||
|
||||
BottomBuilder builder = new BottomBuilder(ctx);
|
||||
|
||||
builder.addTitle(LocaleController.getString("UpdateDownloaded", R.string.UpdateDownloaded));
|
||||
|
||||
builder.addItem(LocaleController.getString("UpdateUpdate", R.string.UpdateUpdate), R.drawable.baseline_system_update_24, false, (it) -> {
|
||||
|
||||
manager.completeUpdate();
|
||||
|
||||
return Unit.INSTANCE;
|
||||
|
||||
});
|
||||
|
||||
builder.addItem(LocaleController.getString("UpdateLater", R.string.UpdateLater), R.drawable.baseline_watch_later_24, false, null);
|
||||
|
||||
try {
|
||||
|
||||
builder.show();
|
||||
|
||||
} catch (WindowManager.BadTokenException e) {
|
||||
|
||||
manager.completeUpdate();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
manager.registerListener(listener);
|
||||
|
||||
manager.getAppUpdateInfo().addOnSuccessListener((appUpdateInfo) -> {
|
||||
|
||||
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE && appUpdateInfo.availableVersionCode() <= BuildConfig.VERSION_CODE) {
|
||||
|
||||
FileLog.d("update available");
|
||||
|
||||
try {
|
||||
|
||||
manager.startUpdateFlowForResult(appUpdateInfo, AppUpdateType.FLEXIBLE, ctx, 114514);
|
||||
|
||||
} catch (IntentSender.SendIntentException ignored) {
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
FileLog.d("no updates");
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
impl.checkUpdate(ctx);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,7 +31,6 @@ import org.telegram.ui.Components.RecyclerListView;
|
|||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import tw.nekomimi.nekogram.parts.UpdateChecksKt;
|
||||
import tw.nekomimi.nekogram.utils.AlertUtil;
|
||||
import tw.nekomimi.nekogram.utils.FileUtil;
|
||||
import tw.nekomimi.nekogram.utils.LocaleUtil;
|
||||
|
|
|
@ -1,95 +0,0 @@
|
|||
|
||||
package tw.nekomimi.nekogram.parts
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.IntentSender
|
||||
import cn.hutool.core.util.StrUtil
|
||||
import com.google.android.play.core.appupdate.AppUpdateManagerFactory
|
||||
import com.google.android.play.core.install.InstallStateUpdatedListener
|
||||
import com.google.android.play.core.install.model.AppUpdateType
|
||||
import com.google.android.play.core.install.model.InstallStatus
|
||||
import com.google.android.play.core.install.model.UpdateAvailability
|
||||
import kotlinx.coroutines.delay
|
||||
import org.json.JSONObject
|
||||
import org.telegram.messenger.BuildConfig
|
||||
import org.telegram.messenger.LocaleController
|
||||
import org.telegram.messenger.R
|
||||
import tw.nekomimi.nekogram.BottomBuilder
|
||||
import tw.nekomimi.nekogram.ExternalGcm
|
||||
import tw.nekomimi.nekogram.NekoXConfig
|
||||
import tw.nekomimi.nekogram.utils.*
|
||||
import java.util.*
|
||||
|
||||
fun Activity.checkUpdate() {
|
||||
|
||||
val progress = AlertUtil.showProgress(this)
|
||||
|
||||
progress.show()
|
||||
|
||||
UIUtil.runOnIoDispatcher {
|
||||
|
||||
progress.uUpdate(LocaleController.getString("Checking", R.string.Checking) + " (Play Store)")
|
||||
|
||||
val manager = AppUpdateManagerFactory.create(this)
|
||||
|
||||
manager.registerListener {
|
||||
|
||||
if (it.installStatus() == InstallStatus.DOWNLOADED) {
|
||||
|
||||
val builder = BottomBuilder(this)
|
||||
|
||||
builder.addTitle(LocaleController.getString("UpdateDownloaded", R.string.UpdateDownloaded))
|
||||
|
||||
builder.addItem(LocaleController.getString("UpdateUpdate", R.string.UpdateUpdate), R.drawable.baseline_system_update_24, false) {
|
||||
|
||||
manager.completeUpdate()
|
||||
|
||||
}
|
||||
|
||||
builder.addItem(LocaleController.getString("UpdateLater", R.string.UpdateLater), R.drawable.baseline_watch_later_24, false, null)
|
||||
|
||||
builder.show()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
manager.appUpdateInfo.addOnSuccessListener {
|
||||
|
||||
progress.dismiss()
|
||||
|
||||
if (it.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE && it.availableVersionCode() > BuildConfig.VERSION_CODE) {
|
||||
|
||||
try {
|
||||
|
||||
manager.startUpdateFlowForResult(it, AppUpdateType.FLEXIBLE, this, 114514)
|
||||
|
||||
} catch (ignored: IntentSender.SendIntentException) {
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
UIUtil.runOnIoDispatcher {
|
||||
|
||||
delay(1000L)
|
||||
|
||||
AlertUtil.showToast(LocaleController.getString("NoUpdate", R.string.NoUpdate))
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}.addOnFailureListener {
|
||||
|
||||
progress.uDismiss()
|
||||
|
||||
AlertUtil.showToast(it.message ?: it.javaClass.simpleName)
|
||||
|
||||
}
|
||||
|
||||
return@runOnIoDispatcher
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -8,7 +8,7 @@ buildscript {
|
|||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:4.1.2'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.30"
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.31"
|
||||
classpath 'com.google.gms:google-services:4.3.5'
|
||||
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.5.0'
|
||||
classpath 'gradle.plugin.org.mozilla.rust-android-gradle:plugin:0.8.3'
|
||||
|
|
Loading…
Reference in New Issue