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

Commit 69bfcd0b authored by Philip P. Moltmann's avatar Philip P. Moltmann
Browse files

Unininstall notifications -> notification channels

Otherwise the uninstall failed notifications are very hidden.

Bonus: IPackageInstall.uninstall thrown IAE when package is already
       uninstalled, at least do not crash.

Test: Faked a failure to uninstall
      Slowed down uninstall to see uninstall notification
Fixes: 35760276

Change-Id: I0ef09e4334df90ac8a70f28149ab4445bcdb60f4
(cherry picked from commit e5bb8d91)
parent 732ec4cb
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -111,6 +111,12 @@
    <string name="uninstall_application_text_user">Do you want to uninstall this app for the user <xliff:g id="username">%1$s</xliff:g>?</string>
    <string name="uninstall_update_text">Replace this app with the factory version? All data will be removed.</string>
    <string name="uninstall_update_text_multiuser">Replace this app with the factory version? All data will be removed. This affects all users of this device, including those with work profiles.</string>

    <!-- Label for the notification channel containing notifications for current uninstall operations [CHAR LIMIT=40] -->
    <string name="uninstalling_notification_channel">Running uninstalls</string>
    <!-- Label for the notification channel containing notifications for failed uninstall operations [CHAR LIMIT=40] -->
    <string name="uninstall_failure_notification_channel">Failed uninstalls</string>

    <string name="uninstalling">Uninstalling\u2026</string>
    <string name="uninstalling_app">Uninstalling <xliff:g id="package_label">%1$s</xliff:g>\u2026</string>
    <string name="uninstall_done">Uninstall finished.</string>
+11 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.packageinstaller;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.admin.IDevicePolicyManager;
@@ -46,6 +47,8 @@ import java.util.List;
public class UninstallFinish extends BroadcastReceiver {
    private static final String LOG_TAG = UninstallFinish.class.getSimpleName();

    private static final String UNINSTALL_FAILURE_CHANNEL = "uninstall failure";

    static final String EXTRA_UNINSTALL_ID = "com.android.packageinstaller.extra.UNINSTALL_ID";
    static final String EXTRA_APP_LABEL = "com.android.packageinstaller.extra.APP_LABEL";

@@ -68,7 +71,14 @@ public class UninstallFinish extends BroadcastReceiver {
                context.getSystemService(NotificationManager.class);
        UserManager userManager = context.getSystemService(UserManager.class);

        Notification.Builder uninstallFailedNotification = new Notification.Builder(context);
        NotificationChannel uninstallFailureChannel = new NotificationChannel(
                UNINSTALL_FAILURE_CHANNEL,
                context.getString(R.string.uninstall_failure_notification_channel),
                NotificationManager.IMPORTANCE_DEFAULT);
        notificationManager.createNotificationChannel(uninstallFailureChannel);

        Notification.Builder uninstallFailedNotification = new Notification.Builder(context,
                UNINSTALL_FAILURE_CHANNEL);

        switch (returnCode) {
            case PackageInstaller.STATUS_SUCCESS:
+13 −5
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.app.DialogFragment;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.ComponentName;
@@ -62,6 +63,8 @@ import java.util.List;
public class UninstallerActivity extends Activity {
    private static final String TAG = "UninstallerActivity";

    private static final String UNINSTALLING_CHANNEL = "uninstalling";

    public static class DialogInfo {
        public ApplicationInfo appInfo;
        public ActivityInfo activityInfo;
@@ -279,14 +282,19 @@ public class UninstallerActivity extends Activity {
            PendingIntent pendingIntent = PendingIntent.getBroadcast(this, uninstallId,
                    broadcastIntent, PendingIntent.FLAG_UPDATE_CURRENT);

            Notification uninstallingNotification = (new Notification.Builder(this))
            NotificationManager notificationManager = getSystemService(NotificationManager.class);
            NotificationChannel uninstallingChannel = new NotificationChannel(UNINSTALLING_CHANNEL,
                    getString(R.string.uninstalling_notification_channel),
                    NotificationManager.IMPORTANCE_MIN);
            notificationManager.createNotificationChannel(uninstallingChannel);

            Notification uninstallingNotification =
                    (new Notification.Builder(this, UNINSTALLING_CHANNEL))
                    .setSmallIcon(R.drawable.ic_remove).setProgress(0, 1, true)
                    .setContentTitle(getString(R.string.uninstalling_app, label)).setOngoing(true)
                    .setPriority(Notification.PRIORITY_MIN)
                    .build();

            getSystemService(NotificationManager.class).notify(uninstallId,
                    uninstallingNotification);
            notificationManager.notify(uninstallId, uninstallingNotification);

            try {
                ActivityThread.getPackageManager().getPackageInstaller().uninstall(
@@ -295,7 +303,7 @@ public class UninstallerActivity extends Activity {
                        getPackageName(), mDialogInfo.allUsers
                                ? PackageManager.DELETE_ALL_USERS : 0,
                        pendingIntent.getIntentSender(), mDialogInfo.user.getIdentifier());
            } catch (RemoteException e) {
            } catch (Exception e) {
                Log.e(TAG, "Cannot start uninstall", e);
                showGenericError();
            }