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

Commit ccf387d6 authored by Anton Hansson's avatar Anton Hansson Committed by Android (Google) Code Review
Browse files

Merge "Pretend to be Settings for location notifications"

parents 54c78252 c22c4d4d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@
    <uses-permission android:name="android.permission.READ_DEVICE_CONFIG" />
    <uses-permission android:name="android.permission.OPEN_ACCESSIBILITY_DETAILS_SETTINGS" />
    <uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE" />
    <uses-permission android:name="android.permission.SUBSTITUTE_NOTIFICATION_APP_NAME" />

    <uses-sdk android:minSdkVersion="28" android:targetSdkVersion="28" />

+22 −0
Original line number Diff line number Diff line
@@ -73,12 +73,14 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.location.LocationManager;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
@@ -554,6 +556,8 @@ public class LocationAccessCheck {
        clickIntent.putExtra(EXTRA_PACKAGE_NAME, pkgName);
        clickIntent.putExtra(EXTRA_USER, user);

        CharSequence appName = getNotificationAppName();

        Notification.Builder b = (new Notification.Builder(mContext,
                PERMISSION_REMINDER_CHANNEL_ID))
                .setContentTitle(mContext.getString(
@@ -570,6 +574,13 @@ public class LocationAccessCheck {
                        FLAG_ONE_SHOT | FLAG_UPDATE_CURRENT))
                .setContentIntent(getBroadcast(mContext, 0, clickIntent,
                        FLAG_ONE_SHOT | FLAG_UPDATE_CURRENT));

        if (appName != null) {
            Bundle extras = new Bundle();
            extras.putString(Notification.EXTRA_SUBSTITUTE_APP_NAME, appName.toString());
            b.addExtras(extras);
        }

        notificationManager.notify(pkgName, LOCATION_ACCESS_CHECK_NOTIFICATION_ID, b.build());

        if (DEBUG) Log.i(LOG_TAG, "Notified " + pkgName);
@@ -578,6 +589,17 @@ public class LocationAccessCheck {
                currentTimeMillis()).apply();
    }

    @Nullable
    private CharSequence getNotificationAppName() {
        // We pretend we're the Settings app sending the notification, so figure out its name.
        Intent openSettingsIntent = new Intent(Settings.ACTION_SETTINGS);
        ResolveInfo resolveInfo = mPackageManager.resolveActivity(openSettingsIntent, 0);
        if (resolveInfo == null) {
            return null;
        }
        return mPackageManager.getApplicationLabel(resolveInfo.activityInfo.applicationInfo);
    }

    /**
     * Get currently shown notification. We only ever show one notification per profile group.
     *