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

Commit 8dd13bf3 authored by Ivan Chiang's avatar Ivan Chiang
Browse files

[PM] Add more logs to debug the flaky test

The CtsPackageInstallerCUJUpdateOwnerShipTestCases is flaky. But, we
can't reproduce it (include ABTD). Let's add more logs to debug it.
After we find the root cause, revert this patch.

Flag: EXEMPT log only update
Bug: 360755710
Test: atest CtsPackageInstallerCUJUpdateOwnerShipTestCases
Change-Id: I03e00aa031a5f2c18c9aba0c0777404ebea41169
parent 6ff9d1ea
Loading
Loading
Loading
Loading
+37 −1
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Process;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
@@ -100,7 +101,8 @@ public class PackageInstallerActivity extends Activity {
    private int mActivityResultCode = Activity.RESULT_CANCELED;
    private int mPendingUserActionReason = -1;

    private final boolean mLocalLOGV = false;
    private final boolean mLocalLOGV =
            TextUtils.equals("userdebug", SystemProperties.get("ro.build.type", ""));
    PackageManager mPm;
    AppOpsManager mAppOpsManager;
    UserManager mUserManager;
@@ -143,6 +145,11 @@ public class PackageInstallerActivity extends Activity {
    private AlertDialog mDialog;

    private void startInstallConfirm() {
        if (mLocalLOGV) {
            Log.d(TAG, "startInstallConfirm mAppInfo = " + mAppInfo
                    + ", existingUpdateOwner = " + getExistingUpdateOwner()
                    + ", mOriginatingPackage = " + mOriginatingPackage);
        }
        TextView viewToEnable;

        if (mAppInfo != null) {
@@ -183,6 +190,10 @@ public class PackageInstallerActivity extends Activity {
        try {
            final String packageName = mPkgInfo.packageName;
            final InstallSourceInfo sourceInfo = mPm.getInstallSourceInfo(packageName);
            if (mLocalLOGV) {
                Log.d(TAG, "getExistingUpdateOwner mAppInfo = " + mAppInfo
                        + ", packageName = " + packageName + ", sourceInfo = " + sourceInfo);
            }
            return sourceInfo.getUpdateOwnerPackageName();
        } catch (NameNotFoundException e) {
            return null;
@@ -303,6 +314,12 @@ public class PackageInstallerActivity extends Activity {

    private void initiateInstall() {
        final String existingUpdateOwner = getExistingUpdateOwner();
        if (mLocalLOGV) {
            Log.d(TAG, "initiateInstall mAppInfo = " + mAppInfo
                    + ", existingUpdateOwner = " + existingUpdateOwner
                    + ", mOriginatingPackage = " + mOriginatingPackage
                    + ", mSessionId = " + mSessionId);
        }
        if (mSessionId == SessionInfo.INVALID_ID &&
            !TextUtils.isEmpty(existingUpdateOwner) &&
            !TextUtils.equals(existingUpdateOwner, mOriginatingPackage)) {
@@ -814,15 +831,28 @@ public class PackageInstallerActivity extends Activity {

        @Override
        public void onOpChanged(String op, String packageName) {
            if (mLocalLOGV) {
                Log.d(TAG, "UnknownSourcesListener onOpChanged op = " + op
                        + ", packageName = " + packageName
                        + ", mOriginatingPackage = " + mOriginatingPackage);
            }
            if (!mOriginatingPackage.equals(packageName)) {
                return;
            }
            unregister(this);
            mActiveUnknownSourcesListeners.remove(this);
            if (mLocalLOGV) {
                Log.d(TAG, "UnknownSourcesListener onOpChanged isDestroyed() = "
                        + isDestroyed());
            }
            if (isDestroyed()) {
                return;
            }
            new Handler(Looper.getMainLooper()).postDelayed(() -> {
                if (mLocalLOGV) {
                    Log.d(TAG, "UnknownSourcesListener onOpChanged post isDestroyed()"
                            + "= " + isDestroyed() + ", getIntent() = " + getIntent());
                }
                if (!isDestroyed()) {
                    startActivity(getIntent());
                    // The start flag (FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP) doesn't
@@ -840,6 +870,9 @@ public class PackageInstallerActivity extends Activity {
    }

    private void register(UnknownSourcesListener listener) {
        if (mLocalLOGV) {
            Log.d(TAG, "UnknownSourcesListener register");
        }
        mAppOpsManager.startWatchingMode(
                AppOpsManager.OPSTR_REQUEST_INSTALL_PACKAGES, mOriginatingPackage,
                listener);
@@ -847,6 +880,9 @@ public class PackageInstallerActivity extends Activity {
    }

    private void unregister(UnknownSourcesListener listener) {
        if (mLocalLOGV) {
            Log.d(TAG, "UnknownSourcesListener unregister");
        }
        mAppOpsManager.stopWatchingMode(listener);
        mActiveUnknownSourcesListeners.remove(listener);
    }
+40 −0
Original line number Diff line number Diff line
@@ -1102,6 +1102,17 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
        final boolean isUpdateOwnershipEnforcementEnabled =
                mPm.isUpdateOwnershipEnforcementAvailable()
                        && existingUpdateOwnerPackageName != null;

        if (Build.IS_USERDEBUG) {
            Log.d("updateowner", "PackageInstallerSession computeUserActionRequirement"
                    + " isUpdateOwnershipEnforcementEnabled= " + isUpdateOwnershipEnforcementEnabled
                    + ", mPm.isUpdateOwnershipEnforcementAvailable= "
                    + mPm.isUpdateOwnershipEnforcementAvailable()
                    + ", existingUpdateOwnerPackageName=" + existingUpdateOwnerPackageName
                    + ", isUpdateOwner= " + isUpdateOwner + ", getInstallerPackageName()= "
                    + getInstallerPackageName() + ", isInstallerShell= " + isInstallerShell
                    + ", mInstallerUid=" + mInstallerUid + ", packageName = " + packageName);
        }
        // For an installation that un-archives an app, if the installer doesn't have the
        // INSTALL_PACKAGES permission, the user should have already been prompted to confirm the
        // un-archive request. There's no need for another confirmation during the installation.
@@ -1115,6 +1126,10 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
                || isInstallUnarchive;

        if (noUserActionNecessary) {
            if (Build.IS_USERDEBUG) {
                Log.d("updateowner", "PackageInstallerSession computeUserActionRequirement"
                                + " noUserActionNecessary userActionNotTypicallyNeededResponse");
            }
            return userActionNotTypicallyNeededResponse;
        }

@@ -1124,15 +1139,27 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
                && !isInstallerShell
                // We don't enforce the update ownership for the managed user and profile.
                && !isFromManagedUserOrProfile) {
            if (Build.IS_USERDEBUG) {
                Log.d("updateowner", "PackageInstallerSession computeUserActionRequirement"
                        + "USER_ACTION_REQUIRED_UPDATE_OWNER_REMINDER");
            }
            return USER_ACTION_REQUIRED_UPDATE_OWNER_REMINDER;
        }

        if (isPermissionGranted) {
            if (Build.IS_USERDEBUG) {
                Log.d("updateowner", "PackageInstallerSession computeUserActionRequirement"
                        + " permission userActionNotTypicallyNeededResponse");
            }
            return userActionNotTypicallyNeededResponse;
        }

        if (snapshot.isInstallDisabledForPackage(getInstallerPackageName(), mInstallerUid,
                userId)) {
            if (Build.IS_USERDEBUG) {
                Log.d("updateowner", "PackageInstallerSession computeUserActionRequirement"
                        + " disable USER_ACTION_REQUIRED");
            }
            // show the installer to account for device policy or unknown sources use cases
            return USER_ACTION_REQUIRED;
        }
@@ -1141,9 +1168,17 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
                && isUpdateWithoutUserActionPermissionGranted
                && ((isUpdateOwnershipEnforcementEnabled ? isUpdateOwner
                : isInstallerOfRecord) || isSelfUpdate)) {
            if (Build.IS_USERDEBUG) {
                Log.d("updateowner", "PackageInstallerSession computeUserActionRequirement"
                        + " USER_ACTION_PENDING_APK_PARSING");
            }
            return USER_ACTION_PENDING_APK_PARSING;
        }

        if (Build.IS_USERDEBUG) {
            Log.d("updateowner", "PackageInstallerSession computeUserActionRequirement"
                    + " USER_ACTION_REQUIRED");
        }
        return USER_ACTION_REQUIRED;
    }

@@ -2714,6 +2749,11 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
        @UserActionRequirement int userActionRequirement = USER_ACTION_NOT_NEEDED;
        // TODO(b/159331446): Move this to makeSessionActiveForInstall and update javadoc
        userActionRequirement = session.computeUserActionRequirement();
        if (Build.IS_USERDEBUG) {
            Log.d("updateowner", "PackageInstallerSession checkUserActionRequirement"
                    + " userActionRequirement= " + userActionRequirement
                    + ", session.packageName= " + session.getPackageName());
        }
        session.updateUserActionRequirement(userActionRequirement);
        if (userActionRequirement == USER_ACTION_REQUIRED
                || userActionRequirement == USER_ACTION_REQUIRED_UPDATE_OWNER_REMINDER) {
+1 −1
Original line number Diff line number Diff line
@@ -340,7 +340,7 @@ public class PackageManagerService implements PackageSender, TestUtilityService
    static final boolean DEBUG_UPGRADE = false;
    static final boolean DEBUG_DOMAIN_VERIFICATION = false;
    static final boolean DEBUG_BACKUP = false;
    public static final boolean DEBUG_INSTALL = false;
    public static final boolean DEBUG_INSTALL = Build.IS_USERDEBUG;
    public static final boolean DEBUG_REMOVE = false;
    static final boolean DEBUG_PACKAGE_INFO = false;
    static final boolean DEBUG_INTENT_MATCHING = false;