Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f4de9502 authored by Jonathan Klee's avatar Jonathan Klee
Browse files

Add/remove AppLounge specifics

parent 0ed4d834
Loading
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -70,10 +70,5 @@
            </intent-filter>
        </activity>

        <receiver android:name="com.android.vending.licensing.LicenseServiceNotificationRunnable$IgnoreReceiver"
            android:exported="false" />
        <receiver android:name="com.android.vending.licensing.LicenseServiceNotificationRunnable$SignInReceiver"
            android:exported="false" />

    </application>
</manifest>
+0 −96
Original line number Diff line number Diff line
@@ -3,43 +3,20 @@ package com.android.vending.licensing;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.util.Log;

import androidx.annotation.CallSuper;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;

import com.android.vending.R;

import java.util.Collections;
import java.util.Set;
import java.util.TreeSet;

public class LicenseServiceNotificationRunnable implements Runnable {

    private final Context context;

    public String callerPackageName;
    public CharSequence callerAppName;
    public int callerUid;

    private static final String TAG = "FakeLicenseNotification";
    private static final String GMS_PACKAGE_NAME = "com.google.android.gms";
    private static final String GMS_AUTH_INTENT_ACTION = "com.google.android.gms.auth.login.LOGIN";

    private static final String PREFERENCES_KEY_IGNORE_PACKAGES_LIST = "ignorePackages";
    private static final String PREFERENCES_FILE_NAME = "licensing";

    private static final String INTENT_KEY_IGNORE_PACKAGE_NAME = "package";
    private static final String INTENT_KEY_NOTIFICATION_ID = "id";


    public LicenseServiceNotificationRunnable(Context context) {
        this.context = context;
    }
@@ -50,44 +27,11 @@ public class LicenseServiceNotificationRunnable implements Runnable {
    public void run() {
        registerNotificationChannel();

        SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_FILE_NAME, Context.MODE_PRIVATE);

        Set<String> ignoreList = preferences.getStringSet(PREFERENCES_KEY_IGNORE_PACKAGES_LIST, Collections.emptySet());
        for (String ignoredPackage : ignoreList) {
            if (callerPackageName.equals(ignoredPackage)) {
                Log.d(TAG, "Not notifying about license check, as user has ignored notifications for package " + ignoredPackage);
                return;
            }
        }

        Intent authIntent = new Intent(context, LicenseServiceNotificationRunnable.SignInReceiver.class);
        authIntent.putExtra(INTENT_KEY_NOTIFICATION_ID, callerUid);
        PendingIntent authPendingIntent = PendingIntent.getBroadcast(
            context, callerUid * 2, authIntent, PendingIntent.FLAG_IMMUTABLE
        );

        Intent ignoreIntent = new Intent(context, LicenseServiceNotificationRunnable.IgnoreReceiver.class);
        ignoreIntent.putExtra(INTENT_KEY_IGNORE_PACKAGE_NAME, callerPackageName);
        ignoreIntent.putExtra(INTENT_KEY_NOTIFICATION_ID, callerUid);
        PendingIntent ignorePendingIntent = PendingIntent.getBroadcast(
            context, callerUid * 2 + 1, ignoreIntent, PendingIntent.FLAG_IMMUTABLE
        );

        Notification notification = new NotificationCompat.Builder(context, CHANNEL_ID)
            .setSmallIcon(R.drawable.ic_notification)
            .setSound(null)
            .setContentTitle(context.getString(R.string.license_notification_title, callerAppName))
            .setContentText(context.getString(R.string.license_notification_body))
            .addAction(
                new NotificationCompat.Action.Builder(
                    null, context.getString(R.string.license_notification_sign_in), authPendingIntent
                ).build()
            )
            .addAction(
                new NotificationCompat.Action.Builder(
                    null, context.getString(R.string.license_notification_ignore), ignorePendingIntent
                ).build()
            )
            .setAutoCancel(true)
            .build();

@@ -109,45 +53,5 @@ public class LicenseServiceNotificationRunnable implements Runnable {
            NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
            notificationManager.createNotificationChannel(channel);
        }

    }

    public static final class IgnoreReceiver extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {

            // Dismiss ignored notification
            NotificationManagerCompat.from(context)
                .cancel(intent.getIntExtra(INTENT_KEY_NOTIFICATION_ID, -1));

            SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_FILE_NAME, Context.MODE_PRIVATE);

            Set<String> ignoreList = new TreeSet<>(
                preferences.getStringSet(PREFERENCES_KEY_IGNORE_PACKAGES_LIST, Collections.emptySet())
            );

            String newIgnorePackage = intent.getStringExtra(INTENT_KEY_IGNORE_PACKAGE_NAME);
            Log.d(TAG, "Adding package " + newIgnorePackage + " to ignore list");

            ignoreList.add(newIgnorePackage);
            preferences.edit().putStringSet(PREFERENCES_KEY_IGNORE_PACKAGES_LIST, ignoreList).apply();
        }
    }

    public static final class SignInReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {

            // Dismiss all notifications
            NotificationManagerCompat.from(context).cancelAll();

            Log.d(TAG, "Starting sign in activity");
            Intent authIntent = new Intent(GMS_AUTH_INTENT_ACTION);
            authIntent.setPackage(GMS_PACKAGE_NAME);
            authIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(authIntent);
        }
    }

}
+1 −4
Original line number Diff line number Diff line
@@ -12,8 +12,5 @@
    <string name="license_notification_channel_name">License notifications</string>
    <string name="license_notification_channel_description">Notifies when an app tries to validate its license, but you are not signed in to any Google account.</string>
    <string name="license_notification_title">%1$s could not verify license</string>
    <string name="license_notification_body">If the app is misbehaving, sign in to a Google account with which you have bought the app.</string>

    <string name="license_notification_sign_in">Sign In</string>
    <string name="license_notification_ignore">Ignore</string>
    <string name="license_notification_body">If the app is misbehaving, sign in to AppLounge or microG.</string>
</resources>
 No newline at end of file