diff --git a/play-services-core/src/main/AndroidManifest.xml b/play-services-core/src/main/AndroidManifest.xml
index 8120ffd922..0f0a5a34f5 100644
--- a/play-services-core/src/main/AndroidManifest.xml
+++ b/play-services-core/src/main/AndroidManifest.xml
@@ -617,6 +617,9 @@
+
+
+
diff --git a/play-services-core/src/main/java/org/microg/gms/ui/AskPushPermission.java b/play-services-core/src/main/java/org/microg/gms/ui/AskPushPermission.java
index f069cb4ec4..735bc4faf7 100644
--- a/play-services-core/src/main/java/org/microg/gms/ui/AskPushPermission.java
+++ b/play-services-core/src/main/java/org/microg/gms/ui/AskPushPermission.java
@@ -1,20 +1,14 @@
package org.microg.gms.ui;
import android.app.Activity;
-import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.ResultReceiver;
-import android.text.Html;
import android.text.Spannable;
import android.text.SpannableString;
-import android.text.SpannableStringBuilder;
-import android.text.Spanned;
-import android.text.SpannedString;
import android.text.style.StyleSpan;
-import android.view.View;
import android.widget.TextView;
import androidx.fragment.app.FragmentActivity;
@@ -22,15 +16,11 @@
import com.google.android.gms.R;
import org.microg.gms.gcm.GcmDatabase;
-import org.microg.gms.gcm.PushRegisterService;
-
-import static org.microg.gms.gcm.GcmConstants.EXTRA_APP;
-import static org.microg.gms.gcm.GcmConstants.EXTRA_KID;
-import static org.microg.gms.gcm.GcmConstants.EXTRA_PENDING_INTENT;
public class AskPushPermission extends FragmentActivity {
public static final String EXTRA_REQUESTED_PACKAGE = "package";
public static final String EXTRA_RESULT_RECEIVER = "receiver";
+ public static final String EXTRA_FORCE_ASK = "force";
public static final String EXTRA_EXPLICIT = "explicit";
private GcmDatabase database;
@@ -47,13 +37,14 @@ public void onCreate(Bundle savedInstanceState) {
packageName = getIntent().getStringExtra(EXTRA_REQUESTED_PACKAGE);
resultReceiver = getIntent().getParcelableExtra(EXTRA_RESULT_RECEIVER);
- if (packageName == null || resultReceiver == null) {
+ boolean force = getIntent().getBooleanExtra(EXTRA_FORCE_ASK, false);
+ if (packageName == null || (resultReceiver == null && !force)) {
answered = true;
finish();
return;
}
- if (database.getApp(packageName) != null) {
+ if (!force && database.getApp(packageName) != null) {
resultReceiver.send(Activity.RESULT_OK, Bundle.EMPTY);
answered = true;
finish();
@@ -71,29 +62,23 @@ public void onCreate(Bundle savedInstanceState) {
s.setSpan(new StyleSpan(Typeface.BOLD), raw.indexOf(label), raw.indexOf(label) + label.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
((TextView) findViewById(R.id.permission_message)).setText(s);
- findViewById(R.id.permission_allow_button).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if (answered) return;
- database.noteAppKnown(packageName, true);
- answered = true;
- Bundle bundle = new Bundle();
- bundle.putBoolean(EXTRA_EXPLICIT, true);
- resultReceiver.send(Activity.RESULT_OK, bundle);
- finish();
- }
+ findViewById(R.id.permission_allow_button).setOnClickListener(v -> {
+ if (answered) return;
+ database.noteAppKnown(packageName, true);
+ answered = true;
+ Bundle bundle = new Bundle();
+ bundle.putBoolean(EXTRA_EXPLICIT, true);
+ if (resultReceiver != null) resultReceiver.send(Activity.RESULT_OK, bundle);
+ finish();
});
- findViewById(R.id.permission_deny_button).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if (answered) return;
- database.noteAppKnown(packageName, false);
- answered = true;
- Bundle bundle = new Bundle();
- bundle.putBoolean(EXTRA_EXPLICIT, true);
- resultReceiver.send(Activity.RESULT_CANCELED, bundle);
- finish();
- }
+ findViewById(R.id.permission_deny_button).setOnClickListener(v -> {
+ if (answered) return;
+ database.noteAppKnown(packageName, false);
+ answered = true;
+ Bundle bundle = new Bundle();
+ bundle.putBoolean(EXTRA_EXPLICIT, true);
+ if (resultReceiver != null) resultReceiver.send(Activity.RESULT_CANCELED, bundle);
+ finish();
});
} catch (PackageManager.NameNotFoundException e) {
finish();
@@ -104,7 +89,7 @@ public void onClick(View v) {
protected void onDestroy() {
super.onDestroy();
if (!answered) {
- resultReceiver.send(Activity.RESULT_CANCELED, Bundle.EMPTY);
+ if (resultReceiver != null) resultReceiver.send(Activity.RESULT_CANCELED, Bundle.EMPTY);
}
database.close();
}
diff --git a/play-services-core/src/main/kotlin/org/microg/gms/accountaction/ErrorResolver.kt b/play-services-core/src/main/kotlin/org/microg/gms/accountaction/ErrorResolver.kt
index 8f9e403647..8c10544625 100644
--- a/play-services-core/src/main/kotlin/org/microg/gms/accountaction/ErrorResolver.kt
+++ b/play-services-core/src/main/kotlin/org/microg/gms/accountaction/ErrorResolver.kt
@@ -53,10 +53,10 @@ fun Context.resolveAuthErrorMessage(s: String): Resolution? = if (s.startsWith("
SettingsContract.CheckIn.LAST_CHECK_IN
)
SettingsContract.getSettings(this, SettingsContract.CheckIn.getContentUri(this), settingsProjection) { cursor ->
- //val checkInEnabled = cursor.getInt(0) != 0
+ val checkInEnabled = cursor.getInt(0) != 0
val lastCheckIn = cursor.getLong(1)
- if (lastCheckIn <= 0) {
+ if (lastCheckIn <= 0 || !checkInEnabled) {
// user is also asked to enable checkin if there had never been a successful checkin (network errors?)
actions += UserAction.ENABLE_CHECKIN
}
diff --git a/play-services-core/src/main/kotlin/org/microg/gms/accountaction/UserInterventionComponents.kt b/play-services-core/src/main/kotlin/org/microg/gms/accountaction/UserInterventionComponents.kt
index a5b4177869..71a8cab2ff 100644
--- a/play-services-core/src/main/kotlin/org/microg/gms/accountaction/UserInterventionComponents.kt
+++ b/play-services-core/src/main/kotlin/org/microg/gms/accountaction/UserInterventionComponents.kt
@@ -1,5 +1,10 @@
package org.microg.gms.accountaction
+import android.app.Activity
+import android.content.Intent
+import android.net.Uri
+import android.os.Bundle
+import android.os.ResultReceiver
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
@@ -21,49 +26,78 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.google.android.gms.R
import org.microg.gms.accountaction.UserAction.*
+import org.microg.gms.common.Constants
+import org.microg.gms.ui.AskPushPermission
+import kotlin.coroutines.resume
+
+const val ACTION_CHECKIN = "org.microg.gms.settings.DEVICE_REGISTRATION_SETTINGS"
+const val ACTION_GCM = "org.microg.gms.settings.GCM_SETTINGS"
+const val ACTION_GCM_APP = "org.microg.gms.settings.GCM_APP_SETTINGS"
+const val URI_GCM_MICROG_APP = "x-gms-settings://gcm/${Constants.GMS_PACKAGE_NAME}"
@Composable
fun UserInterventionComponents(userActions: Map) {
for ((index, action) in userActions.entries.withIndex()) {
+ val context = LocalContext.current as Activity
when (action.component1()) {
ENABLE_CHECKIN -> UserInterventionCommonComponent(
title = stringResource(id = R.string.auth_action_step_enable_checkin),
description = stringResource(id = R.string.auth_action_step_enable_checkin_description),
sequenceNumber = index + 1,
completed = action.component2()
- )
+ ) {
+ Intent(ACTION_CHECKIN).let { context.startActivityForResult(it, 0) }
+ }
ENABLE_GCM -> UserInterventionCommonComponent(
title = stringResource(id = R.string.auth_action_step_enable_gcm),
description = stringResource(id = R.string.auth_action_step_enable_gcm_description),
sequenceNumber = index + 1,
completed = action.component2()
- )
+ ) {
+ Intent(ACTION_GCM).let { context.startActivityForResult(it, 1) }
+ }
ALLOW_MICROG_GCM -> UserInterventionCommonComponent(
title = stringResource(id = R.string.auth_action_step_allow_microg_gcm),
description = stringResource(id = R.string.auth_action_step_allow_microg_gcm_description),
sequenceNumber = index + 1,
completed = action.component2()
- )
+ ) {
+ Intent(context, AskPushPermission::class.java).apply {
+ putExtra(AskPushPermission.EXTRA_REQUESTED_PACKAGE, Constants.GMS_PACKAGE_NAME)
+ putExtra(AskPushPermission.EXTRA_FORCE_ASK, true)
+ addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
+ addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
+ }.let { context.startActivity(it) }
+ }
ENABLE_LOCKSCREEN -> UserInterventionCommonComponent(
title = stringResource(id = R.string.auth_action_step_enable_lockscreen),
description = stringResource(id = R.string.auth_action_step_enable_lockscreen_description),
sequenceNumber = index + 1,
completed = action.component2()
- )
+ ) {
+ runCatching {
+ Intent(android.provider.Settings.ACTION_SECURITY_SETTINGS).let { context.startActivity(it) }
+ }.onFailure {
+ Intent(android.provider.Settings.ACTION_SETTINGS).let { context.startActivity(it) }
+ }
+
+ }
REAUTHENTICATE -> TODO()
}
}
}
@Composable
-fun UserInterventionCommonComponent(title: String, description: String, sequenceNumber: Int?, completed: Boolean) {
- Surface(onClick = { /*TODO*/ }) {
+fun UserInterventionCommonComponent(title: String, description: String, sequenceNumber: Int?, completed: Boolean, onClick: () -> Unit) {
+ Surface(onClick = onClick, enabled = !completed) {
val color = if (completed) {
colorResource(id = R.color.material_success)
diff --git a/play-services-core/src/main/res/layout/ask_gcm.xml b/play-services-core/src/main/res/layout/ask_gcm.xml
index 975afa7b94..5866f892dd 100644
--- a/play-services-core/src/main/res/layout/ask_gcm.xml
+++ b/play-services-core/src/main/res/layout/ask_gcm.xml
@@ -17,8 +17,11 @@
+ android:layout_height="match_parent"
+ android:minWidth="240dp"
+ tools:theme="@style/Theme.App.DayNight.Dialog.Alert.NoActionBar">
+ tools:layout="@layout/device_registration_fragment">
+
+
@@ -75,6 +79,9 @@
+