Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/app/grapheneos/gmscompat/NotableInterface.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package app.grapheneos.gmscompat
import android.Manifest
import android.app.ActivityManager
import android.content.Context
import android.content.pm.GosPackageState
import android.ext.settings.app.AswMissingPlayGamesNotification
import android.util.Log
import app.grapheneos.gmscompat.Const.IS_DEV_BUILD
import com.android.internal.gmscompat.GmsInfo

Expand Down Expand Up @@ -35,9 +38,25 @@ enum class NotableInterface(val ifaceName: String) {
}
}
GamesService -> {

// TODO: Caller package is always Google Play Services so hardcode appPkg for now
val appPkg = "com.playrix.gardenscapes"
val setting = AswMissingPlayGamesNotification.I
val gosPs = GosPackageState.get(appPkg, ctx.userId)
println("NotableInterface ctx.userID: ${ctx.userId}")


val TAG = "showMissingPlayGamesNotification"
Log.d(TAG, "caller: $appPkg")

if (!setting.isNotificationEnabled(gosPs)) {
Log.e(TAG, "notification is disabled")
return
}

Notifications.handleMissingApp(Notifications.CH_MISSING_PLAY_GAMES_APP,
ctx.getString(R.string.missing_play_games_app, getApplicationLabel(ctx, callerPkg)),
"com.google.android.play.games")
ctx.getString(R.string.missing_play_games_app, getApplicationLabel(ctx, appPkg)),
"com.google.android.play.games", appPkg)
}
WearableService -> {
if (processState > ActivityManager.PROCESS_STATE_TOP) {
Expand Down
41 changes: 35 additions & 6 deletions src/app/grapheneos/gmscompat/Notifications.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.app.NotificationManager
import android.app.NotificationManager.IMPORTANCE_HIGH
import android.app.compat.gms.GmsCompat
import android.content.Intent
import android.content.pm.GosPackageStateFlag
import android.content.pm.PackageManager
import android.ext.PackageId
import android.net.Uri
Expand Down Expand Up @@ -46,6 +47,7 @@ object Notifications {
const val ID_MANAGE_PLAY_INTEGRITY_API = 12
const val ID_ENABLE_GOOGLE_CREDENTIAL_PROVIDER = 13
const val ID_MISSING_RCS_PERMISSIONS = 14
const val ID_MISSING_PLAY_GAMES = 15

private val uniqueNotificationId = AtomicInteger(10_000)
fun generateUniqueNotificationId() = uniqueNotificationId.getAndIncrement()
Expand Down Expand Up @@ -188,7 +190,7 @@ object Notifications {
}
}

fun handleMissingApp(channel: String, prompt: CharSequence, appPkg: String) {
fun handleMissingApp(channel: String, prompt: CharSequence, appPkg: String, callerPkg: String? = null) {
if (isPkgInstalled(appPkg)) {
return
}
Expand All @@ -200,15 +202,42 @@ object Notifications {
}

val uri = Uri.parse("market://details?id=$appPkg")
val resolution = Intent(Intent.ACTION_VIEW, uri)
resolution.setPackage(GmsInfo.PACKAGE_PLAY_STORE)
configurationRequired(
val resolutionIntent = Intent(Intent.ACTION_VIEW, uri)
resolutionIntent.setPackage(GmsInfo.PACKAGE_PLAY_STORE)


// The Play Games app is sometimes optional so give the user the option to hide the notification
if (appPkg == "com.google.android.play.games"){
val dontShowAgainIntent = PendingActionReceiver.makeWriteGosPackageStateAndCancelNotif(ctx,
callerPkg, GosPackageStateFlag.SUPPRESS_MISSING_PLAY_GAMES_NOTIF, true,
Notifications.ID_MISSING_PLAY_GAMES)

val dontShowAgainAction = Notification.Action.Builder(null,
ctx.getText(R.string.dont_show_again), dontShowAgainIntent).build()

val pendingIntent = activityPendingIntent(resolutionIntent)
val resolution = Notification.Action.Builder(null, ctx.getText(R.string.install), pendingIntent).build()

builder(CH_MISSING_PLAY_GAMES_APP).apply {
setSmallIcon(R.drawable.ic_configuration_required)
setContentTitle(ctx.getText(R.string.missing_app))
setContentText(prompt)
setStyle(Notification.BigTextStyle())
setAutoCancel(true)
addAction(resolution)
addAction(dontShowAgainAction)
show(Notifications.ID_MISSING_PLAY_GAMES)
}
}
else {
configurationRequired(
channel,
ctx.getText(R.string.missing_app),
prompt,
ctx.getText(R.string.install),
resolution
).show(ID_MISSING_APP)
resolutionIntent
).show(ID_MISSING_APP)
}
}

// returns null if "do not show again" is already set for this notificationId
Expand Down