Commit 21765ed6 authored by Felipe Leme's avatar Felipe Leme Committed by android-build-team Robot

Proper autofill fix to let phone process autofill Settings activity.

Test: adb shell am start com.android.settings/.RadioInfo
Bug: 69981710
Fixes: 70506888

Change-Id: Id29bad2d20b621f7379eb6144c95dcc819949b3d
Merged-In: Id29bad2d20b621f7379eb6144c95dcc819949b3d
(cherry picked from commit 97f16a76db29269619d9a1b45d4cea49026a5b6a)
(cherry picked from commit 92b5d278)
parent 3f89a390
......@@ -268,4 +268,9 @@ public abstract class ActivityManagerInternal {
* @param token The IApplicationToken for the activity
*/
public abstract void setFocusedActivity(IBinder token);
/**
* Returns {@code true} if {@code uid} is running an activity from {@code packageName}.
*/
public abstract boolean hasRunningActivity(int uid, @Nullable String packageName);
}
......@@ -26,6 +26,7 @@ import static com.android.server.autofill.Helper.sVerbose;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.ActivityManagerInternal;
import android.app.AppGlobals;
import android.app.IActivityManager;
import android.content.ComponentName;
......@@ -69,6 +70,7 @@ import com.android.internal.annotations.GuardedBy;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.os.HandlerCaller;
import com.android.server.LocalServices;
import com.android.server.autofill.ui.AutoFillUI;
import java.io.PrintWriter;
......@@ -417,16 +419,17 @@ final class AutofillManagerServiceImpl {
* Asserts the component is owned by the caller.
*/
private void assertCallerLocked(@NonNull ComponentName componentName) {
final String packageName = componentName.getPackageName();
final PackageManager pm = mContext.getPackageManager();
final int callingUid = Binder.getCallingUid();
final int packageUid;
try {
packageUid = pm.getPackageUidAsUser(componentName.getPackageName(),
UserHandle.getCallingUserId());
packageUid = pm.getPackageUidAsUser(packageName, UserHandle.getCallingUserId());
} catch (NameNotFoundException e) {
throw new SecurityException("Could not verify UID for " + componentName);
}
if (callingUid != packageUid) {
if (callingUid != packageUid && !LocalServices.getService(ActivityManagerInternal.class)
.hasRunningActivity(callingUid, packageName)) {
final String[] packages = pm.getPackagesForUid(callingUid);
final String callingPackage = packages != null ? packages[0] : "uid-" + callingUid;
Slog.w(TAG, "App (package=" + callingPackage + ", UID=" + callingUid
......
......@@ -24248,6 +24248,26 @@ public class ActivityManagerService extends IActivityManager.Stub
}
}
}
@Override
public boolean hasRunningActivity(int uid, @Nullable String packageName) {
if (packageName == null) return false;
synchronized (ActivityManagerService.this) {
for (int i = 0; i < mLruProcesses.size(); i++) {
final ProcessRecord processRecord = mLruProcesses.get(i);
if (processRecord.uid == uid) {
for (int j = 0; j < processRecord.activities.size(); j++) {
final ActivityRecord activityRecord = processRecord.activities.get(j);
if (packageName.equals(activityRecord.packageName)) {
return true;
}
}
}
}
}
return false;
}
}
/**
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment