RESTRICT AUTOMERGE Checks cross user permission before handling intent
Bug: 326057017 Test: atest Flag: EXEMPT bug fix (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:d3b3edd45167515579ab156533754e56ac813f35) Merged-In: I3444e55b22b7487f96b0e3e9deb3f844c4c4723a Change-Id: I3444e55b22b7487f96b0e3e9deb3f844c4c4723a
This commit is contained in:
@@ -18,7 +18,9 @@ package com.android.settings.applications;
|
|||||||
|
|
||||||
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.ActivityManager;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.app.admin.DevicePolicyManager;
|
import android.app.admin.DevicePolicyManager;
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
@@ -38,6 +40,7 @@ import android.os.UserManager;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.fragment.app.DialogFragment;
|
import androidx.fragment.app.DialogFragment;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
@@ -134,8 +137,13 @@ public abstract class AppInfoBase extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (intent != null && intent.hasExtra(Intent.EXTRA_USER_HANDLE)) {
|
if (intent != null && intent.hasExtra(Intent.EXTRA_USER_HANDLE)) {
|
||||||
mUserId = ((UserHandle) intent.getParcelableExtra(
|
mUserId = ((UserHandle) intent.getParcelableExtra(Intent.EXTRA_USER_HANDLE))
|
||||||
Intent.EXTRA_USER_HANDLE)).getIdentifier();
|
.getIdentifier();
|
||||||
|
if (mUserId != UserHandle.myUserId() && !hasInteractAcrossUsersPermission()) {
|
||||||
|
Log.w(TAG, "Intent not valid.");
|
||||||
|
finish();
|
||||||
|
return "";
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
mUserId = UserHandle.myUserId();
|
mUserId = UserHandle.myUserId();
|
||||||
}
|
}
|
||||||
@@ -158,6 +166,32 @@ public abstract class AppInfoBase extends SettingsPreferenceFragment
|
|||||||
return mPackageName;
|
return mPackageName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
protected boolean hasInteractAcrossUsersPermission() {
|
||||||
|
Activity activity = getActivity();
|
||||||
|
if (activity == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
String callingPackageName = null;
|
||||||
|
try {
|
||||||
|
callingPackageName = ActivityManager.getService()
|
||||||
|
.getLaunchedFromPackage(activity.getActivityToken());
|
||||||
|
} catch (Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
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) {
|
protected void setIntentAndFinish(boolean appChanged) {
|
||||||
Log.i(TAG, "appChanged=" + appChanged);
|
Log.i(TAG, "appChanged=" + appChanged);
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
|
Reference in New Issue
Block a user