Intersect requestedPermissions with that of current update's one
Fixes: 120092266 Test: - install apk https://drive.google.com/file/d/1eh2mCz-0Ymm4TghOaf46ZHdn2-M8bm6i/view?usp=sharing - hardcode DefaultPermissionGrantPolicy to always run on reboot - adb reboot - ensure device bootloobs with an error from attached bug - apply fix - ensure device no longer bootloops - ensure no error in logcat Change-Id: If2387e963b63231b0b99a55fdb7e75187d07bd07
This commit is contained in:
@@ -32,6 +32,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.IntFunction;
|
||||
|
||||
/**
|
||||
* ArrayUtils contains some methods that you can call to find out
|
||||
@@ -656,4 +657,30 @@ public class ArrayUtils {
|
||||
throw new ArrayIndexOutOfBoundsException("length=" + len + "; index=" + index);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array with values from {@code val} minus {@code null} values
|
||||
*
|
||||
* @param arrayConstructor typically {@code T[]::new} e.g. {@code String[]::new}
|
||||
*/
|
||||
public static <T> T[] filterNotNull(T[] val, IntFunction<T[]> arrayConstructor) {
|
||||
int nullCount = 0;
|
||||
int size = size(val);
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (val[i] == null) {
|
||||
nullCount++;
|
||||
}
|
||||
}
|
||||
if (nullCount == 0) {
|
||||
return val;
|
||||
}
|
||||
T[] result = arrayConstructor.apply(size - nullCount);
|
||||
int outIdx = 0;
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (val[i] != null) {
|
||||
result[outIdx++] = val[i];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,6 @@ import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.os.SystemProperties;
|
||||
import android.os.UserHandle;
|
||||
import android.os.storage.StorageManager;
|
||||
import android.permission.PermissionManager;
|
||||
@@ -1059,6 +1058,17 @@ public final class DefaultPermissionGrantPolicy {
|
||||
return;
|
||||
}
|
||||
|
||||
// Intersect the requestedPermissions for a factory image with that of its current update
|
||||
// in case the latter one removed a <uses-permission>
|
||||
String[] requestedByNonSystemPackage = getPackageInfo(pkg.packageName).requestedPermissions;
|
||||
int size = requestedPermissions.length;
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (!ArrayUtils.contains(requestedByNonSystemPackage, requestedPermissions[i])) {
|
||||
requestedPermissions[i] = null;
|
||||
}
|
||||
}
|
||||
requestedPermissions = ArrayUtils.filterNotNull(requestedPermissions, String[]::new);
|
||||
|
||||
PackageManager pm = mContext.getPackageManager();
|
||||
final ArraySet<String> permissions = new ArraySet<>(permissionsWithoutSplits);
|
||||
ApplicationInfo applicationInfo = pkg.applicationInfo;
|
||||
|
||||
Reference in New Issue
Block a user