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

Commit 250fb72f authored by Philip P. Moltmann's avatar Philip P. Moltmann
Browse files

Uninstaller: Check if allowed early

Run check for whether the user can request an uninstallation in
UninstallerActivity. This means that this now runs before the user
confirms to uninstall a package. This adds a new failure dialog in
UserIsNotAllowedDialogFragment.

Bonus: move dialog buttons to the right (neutral -> positive) where they
       belong according to material design spec.

Test: Simulated a failure and saw UI.
Change-Id: Id3e3ade62d5422d0dc2cbda0ab91da0d7f5afed1
parent e6163b3d
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -98,6 +98,8 @@
    <string name="dlg_ok">OK</string>
    <string name="app_not_found_dlg_title">App not found</string>
    <string name="app_not_found_dlg_text"> The app wasn\'t found in the list of installed apps.</string>
    <string name="user_is_not_allowed_dlg_title">Not allowed</string>
    <string name="user_is_not_allowed_dlg_text">The current user is not allowed to perform this uninstallation.</string>
    <string name="uninstall_application_title">Uninstall app</string>
    <string name="uninstall_update_title">Uninstall update</string>
    <string name="uninstall_activity_text"><xliff:g id="activity_name">%1$s</xliff:g> is part of the following app:</string>
+0 −10
Original line number Diff line number Diff line
@@ -275,19 +275,9 @@ public class UninstallAppProgress extends Activity {
        }

        mAllUsers = intent.getBooleanExtra(Intent.EXTRA_UNINSTALL_ALL_USERS, false);
        if (mAllUsers && !UserManager.get(this).isAdminUser()) {
            throw new SecurityException("Only admin user can request uninstall for all users");
        }
        UserHandle user = intent.getParcelableExtra(Intent.EXTRA_USER);
        if (user == null) {
            user = android.os.Process.myUserHandle();
        } else {
            UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
            List<UserHandle> profiles = userManager.getUserProfiles();
            if (!profiles.contains(user)) {
                throw new SecurityException("User " + android.os.Process.myUserHandle() + " can't "
                        + "request uninstall for user " + user);
            }
        }

        PackageDeleteObserver observer = new PackageDeleteObserver();
+28 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
@@ -38,13 +39,17 @@ import android.os.IBinder;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.os.UserManager;
import android.util.Log;

import com.android.packageinstaller.handheld.AppNotFoundDialogFragment;
import com.android.packageinstaller.handheld.UninstallAlertDialogFragment;
import com.android.packageinstaller.handheld.UserIsNotAllowedDialogFragment;
import com.android.packageinstaller.television.AppNotFoundFragment;
import com.android.packageinstaller.television.UninstallAlertFragment;
import com.android.packageinstaller.television.UserIsNotAllowedFragment;

import java.util.List;
import java.util.Random;

/*
@@ -91,12 +96,26 @@ public class UninstallerActivity extends Activity {

        mDialogInfo = new DialogInfo();

        mDialogInfo.allUsers = intent.getBooleanExtra(Intent.EXTRA_UNINSTALL_ALL_USERS, false);
        if (mDialogInfo.allUsers && !UserManager.get(this).isAdminUser()) {
            Log.e(TAG, "Only admin user can request uninstall for all users");
            showUserIsNotAllowed();
            return;
        }
        mDialogInfo.user = intent.getParcelableExtra(Intent.EXTRA_USER);
        if (mDialogInfo.user == null) {
            mDialogInfo.user = android.os.Process.myUserHandle();
        } else {
            UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
            List<UserHandle> profiles = userManager.getUserProfiles();
            if (!profiles.contains(mDialogInfo.user)) {
                Log.e(TAG, "User " + android.os.Process.myUserHandle() + " can't request uninstall "
                        + "for user " + mDialogInfo.user);
                showUserIsNotAllowed();
                return;
            }
        }

        mDialogInfo.allUsers = intent.getBooleanExtra(Intent.EXTRA_UNINSTALL_ALL_USERS, false);
        mDialogInfo.callback = intent.getIBinderExtra(PackageInstaller.EXTRA_CALLBACK);

        try {
@@ -148,6 +167,14 @@ public class UninstallerActivity extends Activity {
        }
    }

    private void showUserIsNotAllowed() {
        if (isTv()) {
            showContentFragment(new UserIsNotAllowedFragment());
        } else {
            showDialogFragment(new UserIsNotAllowedDialogFragment());
        }
    }

    private boolean isTv() {
        return (getResources().getConfiguration().uiMode & Configuration.UI_MODE_TYPE_MASK)
                == Configuration.UI_MODE_TYPE_TELEVISION;
+1 −1
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ public class AppNotFoundDialogFragment extends DialogFragment {
        return new AlertDialog.Builder(getActivity())
                .setTitle(R.string.app_not_found_dlg_title)
                .setMessage(R.string.app_not_found_dlg_text)
                .setNeutralButton(android.R.string.ok, null)
                .setPositiveButton(android.R.string.ok, null)
                .create();
    }

+50 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.packageinstaller.handheld;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;

import com.android.packageinstaller.R;
import com.android.packageinstaller.UninstallerActivity;

/**
 * A dialog telling the user that he/she is currently not allowed to perform this uninstallation.
 */
public class UserIsNotAllowedDialogFragment extends DialogFragment {
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        return new AlertDialog.Builder(getActivity())
                .setMessage(R.string.user_is_not_allowed_dlg_text)
                .setPositiveButton(android.R.string.ok, null)
                .create();
    }

    @Override
    public void onDismiss(DialogInterface dialog) {
        super.onDismiss(dialog);
        if (isAdded()) {
            ((UninstallerActivity) getActivity()).dispatchAborted();
            getActivity().setResult(Activity.RESULT_FIRST_USER);
            getActivity().finish();
        }
    }
}
Loading