Skip to content

Commit

Permalink
Checks cross user permission before handling intent
Browse files Browse the repository at this point in the history
Bug: 326057017

Test: atest

Flag: EXEMPT bug fix
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:d3b3edd45167515579ab156533754e56ac813f35)
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:4a066bc09106566c7f77b0fca69579c3383132fe)
Merged-In: I3444e55b22b7487f96b0e3e9deb3f844c4c4723a
Change-Id: I3444e55b22b7487f96b0e3e9deb3f844c4c4723a
  • Loading branch information
Fan Wu authored and aoleary committed Nov 18, 2024
1 parent 6a49291 commit 18f989e
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions src/com/android/settings/applications/AppInfoBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;

import android.Manifest;
import android.app.Activity;
import android.app.Dialog;
import android.app.admin.DevicePolicyManager;
Expand All @@ -38,6 +39,7 @@
import android.text.TextUtils;
import android.util.Log;

import androidx.annotation.VisibleForTesting;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
Expand Down Expand Up @@ -134,8 +136,13 @@ protected String retrieveAppEntry() {
}
}
if (intent != null && intent.hasExtra(Intent.EXTRA_USER_HANDLE)) {
mUserId = ((UserHandle) intent.getParcelableExtra(
Intent.EXTRA_USER_HANDLE)).getIdentifier();
mUserId = ((UserHandle) intent.getParcelableExtra(Intent.EXTRA_USER_HANDLE))
.getIdentifier();
if (mUserId != UserHandle.myUserId() && !hasInteractAcrossUsersPermission()) {
Log.w(TAG, "Intent not valid.");
finish();
return "";
}
} else {
mUserId = UserHandle.myUserId();
}
Expand All @@ -158,6 +165,28 @@ protected String retrieveAppEntry() {
return mPackageName;
}

@VisibleForTesting
protected boolean hasInteractAcrossUsersPermission() {
Activity activity = getActivity();
if (!(activity instanceof SettingsActivity)) {
return false;
}
final String callingPackageName =
((SettingsActivity) activity).getInitialCallingPackage();

if (TextUtils.isEmpty(callingPackageName)) {
Log.w(TAG, "Not able to get calling package name for permission check");
return false;
}
if (mPm.checkPermission(Manifest.permission.INTERACT_ACROSS_USERS_FULL, callingPackageName)
!= PackageManager.PERMISSION_GRANTED) {
Log.w(TAG, "Package " + callingPackageName + " does not have required permission "
+ Manifest.permission.INTERACT_ACROSS_USERS_FULL);
return false;
}
return true;
}

protected void setIntentAndFinish(boolean appChanged) {
Log.i(TAG, "appChanged=" + appChanged);
Intent intent = new Intent();
Expand Down

0 comments on commit 18f989e

Please sign in to comment.