mirror of
https://github.com/TeamVanced/VancedMicroG
synced 2025-02-02 14:07:32 +01:00
Revert "Fix NullReferenceException" and add a95f644 + 93636a7
This commit is contained in:
parent
eb6f2b2fc7
commit
052603588a
@ -543,6 +543,7 @@ public class McsService extends Service implements Handler.Callback {
|
||||
|
||||
if (receiverPermission == null) {
|
||||
// Without receiver permission, we only restrict by package name
|
||||
if (app.wakeForDelivery) addPowerSaveTempWhitelistApp(packageName);
|
||||
logd(this, "Deliver message to all receivers in package " + packageName);
|
||||
intent.setPackage(packageName);
|
||||
sendOrderedBroadcast(intent, null);
|
||||
@ -555,18 +556,7 @@ public class McsService extends Service implements Handler.Callback {
|
||||
Intent targetIntent = new Intent(intent);
|
||||
targetIntent.setComponent(new ComponentName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name));
|
||||
if (resolveInfo.activityInfo.packageName.equals(packageName)) {
|
||||
// Wake up the package itself
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && app.wakeForDelivery) {
|
||||
try {
|
||||
if (getUserIdMethod != null && addPowerSaveTempWhitelistAppMethod != null && deviceIdleController != null) {
|
||||
int userId = (int) getUserIdMethod.invoke(null, getPackageManager().getApplicationInfo(packageName, 0).uid);
|
||||
logd(this, "Adding app " + packageName + " for userId " + userId + " to the temp whitelist");
|
||||
addPowerSaveTempWhitelistAppMethod.invoke(deviceIdleController, packageName, 10000, userId, "GCM Push");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, e);
|
||||
}
|
||||
}
|
||||
if (app.wakeForDelivery) addPowerSaveTempWhitelistApp(packageName);
|
||||
// We don't need receiver permission for our own package
|
||||
logd(this, "Deliver message to own receiver " + resolveInfo);
|
||||
sendOrderedBroadcast(targetIntent, null);
|
||||
@ -580,6 +570,20 @@ public class McsService extends Service implements Handler.Callback {
|
||||
}
|
||||
}
|
||||
|
||||
private void addPowerSaveTempWhitelistApp(String packageName) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
try {
|
||||
if (getUserIdMethod != null && addPowerSaveTempWhitelistAppMethod != null && deviceIdleController != null) {
|
||||
int userId = (int) getUserIdMethod.invoke(null, getPackageManager().getApplicationInfo(packageName, 0).uid);
|
||||
logd(this, "Adding app " + packageName + " for userId " + userId + " to the temp whitelist");
|
||||
addPowerSaveTempWhitelistAppMethod.invoke(deviceIdleController, packageName, 10000, userId, "GCM Push");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleSelfMessage(DataMessageStanza msg) {
|
||||
for (AppData appData : msg.app_data) {
|
||||
if (IDLE_NOTIFICATION.equals(appData.key)) {
|
||||
|
@ -53,30 +53,28 @@ private suspend fun ensureCheckinIsUpToDate(context: Context) {
|
||||
}
|
||||
|
||||
private suspend fun ensureAppRegistrationAllowed(context: Context, database: GcmDatabase, packageName: String) {
|
||||
try {
|
||||
if (!GcmPrefs.get(context).isEnabled) throw RuntimeException("GCM disabled")
|
||||
val app = database.getApp(packageName)
|
||||
if (app == null && GcmPrefs.get(context).isConfirmNewApps) {
|
||||
val accepted: Boolean = suspendCoroutine { continuation ->
|
||||
val i = Intent(context, AskPushPermission::class.java)
|
||||
i.putExtra(AskPushPermission.EXTRA_REQUESTED_PACKAGE, packageName)
|
||||
i.putExtra(AskPushPermission.EXTRA_RESULT_RECEIVER, object : ResultReceiver(null) {
|
||||
override fun onReceiveResult(resultCode: Int, resultData: Bundle?) {
|
||||
continuation.resume(resultCode == Activity.RESULT_OK)
|
||||
}
|
||||
})
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
|
||||
context.startActivity(i)
|
||||
}
|
||||
if (!accepted) {
|
||||
throw RuntimeException("Push permission not granted to app")
|
||||
}
|
||||
} else if (!app.allowRegister) {
|
||||
if (!GcmPrefs.get(context).isEnabled) throw RuntimeException("GCM disabled")
|
||||
val app = database.getApp(packageName)
|
||||
if (app == null && GcmPrefs.get(context).isConfirmNewApps) {
|
||||
val accepted: Boolean = suspendCoroutine { continuation ->
|
||||
val i = Intent(context, AskPushPermission::class.java)
|
||||
i.putExtra(AskPushPermission.EXTRA_REQUESTED_PACKAGE, packageName)
|
||||
i.putExtra(AskPushPermission.EXTRA_RESULT_RECEIVER, object : ResultReceiver(null) {
|
||||
override fun onReceiveResult(resultCode: Int, resultData: Bundle?) {
|
||||
continuation.resume(resultCode == Activity.RESULT_OK)
|
||||
}
|
||||
})
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
|
||||
context.startActivity(i)
|
||||
}
|
||||
if (!accepted) {
|
||||
throw RuntimeException("Push permission not granted to app")
|
||||
}
|
||||
} catch (e: Exception) {}
|
||||
} else if (app?.allowRegister) {
|
||||
throw RuntimeException("Push permission not granted to app")
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun completeRegisterRequest(context: Context, database: GcmDatabase, request: RegisterRequest, requestId: String? = null): Bundle = suspendCoroutine { continuation ->
|
||||
|
Loading…
x
Reference in New Issue
Block a user