[Settings] Passing correct user id to getAppOpPermissionPackages
A new user id parameter is added to the IPackageManager#getAppOpPermissionPackages API. Update the new api usage to the Settings application. Bug: 229684723 Test: atest SettingsUnitTests Test: m -j RunSettingsRoboTests \ ROBOTEST_FILTER="AlarmsAndRemindersDetailsTest| AlarmsAndRemindersDetailPreferenceControllerTest" Change-Id: I8c90f0a57426c669478367004571cca5dfb05cb6
This commit is contained in:
@@ -57,7 +57,7 @@ public class AppStateAlarmsAndRemindersBridge extends AppStateBaseBridge {
|
|||||||
mAlarmManager = context.getSystemService(AlarmManager.class);
|
mAlarmManager = context.getSystemService(AlarmManager.class);
|
||||||
final IPackageManager iPm = AppGlobals.getPackageManager();
|
final IPackageManager iPm = AppGlobals.getPackageManager();
|
||||||
try {
|
try {
|
||||||
mRequesterPackages = iPm.getAppOpPermissionPackages(PERMISSION);
|
mRequesterPackages = iPm.getAppOpPermissionPackages(PERMISSION, context.getUserId());
|
||||||
} catch (RemoteException re) {
|
} catch (RemoteException re) {
|
||||||
Log.e(TAG, "Cannot reach package manager", re);
|
Log.e(TAG, "Cannot reach package manager", re);
|
||||||
mRequesterPackages = EmptyArray.STRING;
|
mRequesterPackages = EmptyArray.STRING;
|
||||||
|
@@ -172,25 +172,25 @@ public abstract class AppStateAppOpsBridge extends AppStateBaseBridge {
|
|||||||
*/
|
*/
|
||||||
private SparseArray<ArrayMap<String, PermissionState>> getEntries() {
|
private SparseArray<ArrayMap<String, PermissionState>> getEntries() {
|
||||||
try {
|
try {
|
||||||
Set<String> packagesSet = new HashSet<>();
|
|
||||||
for (String permission : mPermissions) {
|
|
||||||
String[] pkgs = mIPackageManager.getAppOpPermissionPackages(permission);
|
|
||||||
if (pkgs != null) {
|
|
||||||
packagesSet.addAll(Arrays.asList(pkgs));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (packagesSet.isEmpty()) {
|
|
||||||
// No packages are requesting permission as specified by mPermissions.
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a sparse array that maps profileIds to an ArrayMap that maps package names to
|
// Create a sparse array that maps profileIds to an ArrayMap that maps package names to
|
||||||
// an associated PermissionState object
|
// an associated PermissionState object
|
||||||
SparseArray<ArrayMap<String, PermissionState>> entries = new SparseArray<>();
|
SparseArray<ArrayMap<String, PermissionState>> entries = new SparseArray<>();
|
||||||
for (final UserHandle profile : mProfiles) {
|
for (final UserHandle profile : mProfiles) {
|
||||||
final ArrayMap<String, PermissionState> entriesForProfile = new ArrayMap<>();
|
|
||||||
final int profileId = profile.getIdentifier();
|
final int profileId = profile.getIdentifier();
|
||||||
|
final Set<String> packagesSet = new HashSet<>();
|
||||||
|
for (String permission : mPermissions) {
|
||||||
|
final String[] pkgs = mIPackageManager.getAppOpPermissionPackages(
|
||||||
|
permission, profileId);
|
||||||
|
if (pkgs != null) {
|
||||||
|
packagesSet.addAll(Arrays.asList(pkgs));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (packagesSet.isEmpty()) {
|
||||||
|
// No packages are requesting permission as specified by mPermissions.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
final ArrayMap<String, PermissionState> entriesForProfile = new ArrayMap<>();
|
||||||
entries.put(profileId, entriesForProfile);
|
entries.put(profileId, entriesForProfile);
|
||||||
for (final String packageName : packagesSet) {
|
for (final String packageName : packagesSet) {
|
||||||
final boolean isAvailable = mIPackageManager.isPackageAvailable(packageName,
|
final boolean isAvailable = mIPackageManager.isPackageAvailable(packageName,
|
||||||
@@ -201,6 +201,9 @@ public abstract class AppStateAppOpsBridge extends AppStateBaseBridge {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (entries.size() == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return entries;
|
return entries;
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
|
@@ -22,6 +22,7 @@ import android.content.Context;
|
|||||||
import android.content.pm.IPackageManager;
|
import android.content.pm.IPackageManager;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
|
import android.os.UserHandle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.internal.util.ArrayUtils;
|
import com.android.internal.util.ArrayUtils;
|
||||||
@@ -65,9 +66,9 @@ public class AppStateInstallAppsBridge extends AppStateBaseBridge {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasRequestedAppOpPermission(String permission, String packageName) {
|
private boolean hasRequestedAppOpPermission(String permission, String packageName, int userId) {
|
||||||
try {
|
try {
|
||||||
String[] packages = mIpm.getAppOpPermissionPackages(permission);
|
String[] packages = mIpm.getAppOpPermissionPackages(permission, userId);
|
||||||
return ArrayUtils.contains(packages, packageName);
|
return ArrayUtils.contains(packages, packageName);
|
||||||
} catch (RemoteException exc) {
|
} catch (RemoteException exc) {
|
||||||
Log.e(TAG, "PackageManager dead. Cannot get permission info");
|
Log.e(TAG, "PackageManager dead. Cannot get permission info");
|
||||||
@@ -91,8 +92,9 @@ public class AppStateInstallAppsBridge extends AppStateBaseBridge {
|
|||||||
|
|
||||||
public InstallAppsState createInstallAppsStateFor(String packageName, int uid) {
|
public InstallAppsState createInstallAppsStateFor(String packageName, int uid) {
|
||||||
final InstallAppsState appState = new InstallAppsState();
|
final InstallAppsState appState = new InstallAppsState();
|
||||||
|
final int userId = UserHandle.getUserId(uid);
|
||||||
appState.permissionRequested = hasRequestedAppOpPermission(
|
appState.permissionRequested = hasRequestedAppOpPermission(
|
||||||
Manifest.permission.REQUEST_INSTALL_PACKAGES, packageName);
|
Manifest.permission.REQUEST_INSTALL_PACKAGES, packageName, userId);
|
||||||
appState.appOpMode = getAppOpMode(AppOpsManager.OP_REQUEST_INSTALL_PACKAGES, uid,
|
appState.appOpMode = getAppOpMode(AppOpsManager.OP_REQUEST_INSTALL_PACKAGES, uid,
|
||||||
packageName);
|
packageName);
|
||||||
return appState;
|
return appState;
|
||||||
|
Reference in New Issue
Block a user