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

Commit d55449ae authored by Nate Myren's avatar Nate Myren
Browse files

Add Auto Revoke log to the App Info page

Test: manual
Bug: 154650244
Change-Id: Ibc944ce72d176204cc20c6d0460bf5efe6f7a878
parent 73d33679
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -16,6 +16,10 @@

package com.android.settings.applications.appinfo;

import static com.android.settings.core.instrumentation.SettingsStatsLog.AUTO_REVOKED_APP_INTERACTION;
import static com.android.settings.core.instrumentation.SettingsStatsLog.AUTO_REVOKED_APP_INTERACTION__ACTION__OPEN_IN_SETTINGS;
import static com.android.settings.core.instrumentation.SettingsStatsLog.AUTO_REVOKED_APP_INTERACTION__ACTION__REMOVE_IN_SETTINGS;

import android.app.Activity;
import android.app.ActivityManager;
import android.app.admin.DevicePolicyManager;
@@ -52,6 +56,7 @@ import com.android.settings.applications.specialaccess.deviceadmin.DeviceAdminAd
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.InstrumentedPreferenceFragment;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.core.instrumentation.SettingsStatsLog;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedLockUtilsInternal;
@@ -118,10 +123,12 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp
    private RestrictedLockUtils.EnforcedAdmin mAppsControlDisallowedAdmin;
    private PreferenceScreen mScreen;

    private long mSessionId;
    private boolean mUpdatedSysApp = false;
    private boolean mListeningToPackageRemove = false;
    private boolean mFinishing = false;
    private boolean mAppsControlDisallowedBySystem;
    private boolean mAccessedFromAutoRevoke;

    public AppButtonsPreferenceController(SettingsActivity activity,
            InstrumentedPreferenceFragment fragment,
@@ -149,6 +156,8 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp
        mRequestUninstall = requestUninstall;
        mRequestRemoveDeviceAdmin = requestRemoveDeviceAdmin;
        mAppLaunchIntent = mPm.getLaunchIntentForPackage(mPackageName);
        mSessionId = activity.getIntent().getLongExtra(Intent.ACTION_AUTO_REVOKE_PERMISSIONS, 0);
        mAccessedFromAutoRevoke = mSessionId != 0;

        if (packageName != null) {
            mAppEntry = mState.getEntry(packageName, mUserId);
@@ -202,6 +211,13 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp

        @Override
        public void onClick(View v) {
            if (mAccessedFromAutoRevoke) {

                Log.i(TAG, "sessionId: " + mSessionId + " uninstalling " + mPackageName
                        + " with uid " + getUid() + ", reached from auto revoke");
                SettingsStatsLog.write(AUTO_REVOKED_APP_INTERACTION, mSessionId, getUid(),
                        mPackageName, AUTO_REVOKED_APP_INTERACTION__ACTION__REMOVE_IN_SETTINGS);
            }
            final String packageName = mAppEntry.info.packageName;
            // Uninstall
            if (mDpm.packageHasActiveAdmins(mPackageInfo.packageName)) {
@@ -701,10 +717,28 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp

    private void launchApplication() {
        if (mAppLaunchIntent != null) {
            if (mAccessedFromAutoRevoke) {

                Log.i(TAG, "sessionId: " + mSessionId + " uninstalling " + mPackageName
                        + " with uid " + getUid() + ", reached from auto revoke");
                SettingsStatsLog.write(AUTO_REVOKED_APP_INTERACTION, mSessionId, getUid(),
                        mPackageName, AUTO_REVOKED_APP_INTERACTION__ACTION__OPEN_IN_SETTINGS);
            }
            mContext.startActivityAsUser(mAppLaunchIntent, new UserHandle(mUserId));
        }
    }

    private int getUid() {
        int uid = -1;
        if (mPackageInfo == null) {
            retrieveAppEntry();
        }
        if (mPackageInfo != null) {
            uid = mPackageInfo.applicationInfo.uid;
        }
        return uid;
    }

    private boolean isInstantApp() {
        return mAppEntry != null && AppUtils.isInstant(mAppEntry.info);
    }
+12 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import com.android.settingslib.core.lifecycle.events.OnStop;

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

/**
 * A PreferenceController handling the logic for permissions of apps.
@@ -44,6 +45,7 @@ public class AppPermissionPreferenceController extends AppInfoPreferenceControll

    private static final String TAG = "PermissionPrefControl";
    private static final String EXTRA_HIDE_INFO_BUTTON = "hideInfoButton";
    private static final long INVALID_SESSION_ID = 0;

    private final PackageManager mPackageManager;

@@ -124,6 +126,16 @@ public class AppPermissionPreferenceController extends AppInfoPreferenceControll
        final Intent intent = new Intent(Intent.ACTION_MANAGE_APP_PERMISSIONS);
        intent.putExtra(Intent.EXTRA_PACKAGE_NAME, mParent.getAppEntry().info.packageName);
        intent.putExtra(EXTRA_HIDE_INFO_BUTTON, true);
        String action = mParent.getActivity().getIntent().getAction();
        long sessionId = mParent.getActivity().getIntent().getLongExtra(
                Intent.ACTION_AUTO_REVOKE_PERMISSIONS, INVALID_SESSION_ID);
        if ((action != null && action.equals(Intent.ACTION_AUTO_REVOKE_PERMISSIONS))
                || sessionId != INVALID_SESSION_ID) {
            while (sessionId == INVALID_SESSION_ID) {
                sessionId = new Random().nextLong();
            }
            intent.putExtra(Intent.ACTION_AUTO_REVOKE_PERMISSIONS, sessionId);
        }
        try {
            mParent.getActivity().startActivityForResult(intent, mParent.SUB_INFO_FRAGMENT);
        } catch (ActivityNotFoundException e) {