Include uid in device admin pref id.
Fixes: 124979213 Test: robotests Change-Id: I50114db79e9b5278bc916fbbba6353c5f19df24f
This commit is contained in:
@@ -30,6 +30,7 @@ class DeviceAdminListItem implements Comparable<DeviceAdminListItem> {
|
|||||||
|
|
||||||
private static final String TAG = "DeviceAdminListItem";
|
private static final String TAG = "DeviceAdminListItem";
|
||||||
|
|
||||||
|
private final UserHandle mUserHandle;
|
||||||
private final String mKey;
|
private final String mKey;
|
||||||
private final DeviceAdminInfo mInfo;
|
private final DeviceAdminInfo mInfo;
|
||||||
private final CharSequence mName;
|
private final CharSequence mName;
|
||||||
@@ -39,7 +40,8 @@ class DeviceAdminListItem implements Comparable<DeviceAdminListItem> {
|
|||||||
|
|
||||||
public DeviceAdminListItem(Context context, DeviceAdminInfo info) {
|
public DeviceAdminListItem(Context context, DeviceAdminInfo info) {
|
||||||
mInfo = info;
|
mInfo = info;
|
||||||
mKey = mInfo.getComponent().flattenToString();
|
mUserHandle = new UserHandle(getUserIdFromDeviceAdminInfo(mInfo));
|
||||||
|
mKey = mUserHandle.getIdentifier() + "@" + mInfo.getComponent().flattenToString();
|
||||||
mDPM = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
|
mDPM = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||||
final PackageManager pm = context.getPackageManager();
|
final PackageManager pm = context.getPackageManager();
|
||||||
mName = mInfo.loadLabel(pm);
|
mName = mInfo.loadLabel(pm);
|
||||||
@@ -48,8 +50,7 @@ class DeviceAdminListItem implements Comparable<DeviceAdminListItem> {
|
|||||||
} catch (Resources.NotFoundException exception) {
|
} catch (Resources.NotFoundException exception) {
|
||||||
Log.w(TAG, "Setting description to null because can't find resource: " + mKey);
|
Log.w(TAG, "Setting description to null because can't find resource: " + mKey);
|
||||||
}
|
}
|
||||||
mIcon = pm.getUserBadgedIcon(mInfo.loadIcon(pm),
|
mIcon = pm.getUserBadgedIcon(mInfo.loadIcon(pm), mUserHandle);
|
||||||
new UserHandle(DeviceAdminUtils.getUserIdFromDeviceAdminInfo(mInfo)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -70,8 +71,7 @@ class DeviceAdminListItem implements Comparable<DeviceAdminListItem> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isActive() {
|
public boolean isActive() {
|
||||||
return mDPM.isAdminActiveAsUser(mInfo.getComponent(),
|
return mDPM.isAdminActiveAsUser(mInfo.getComponent(), getUserIdFromDeviceAdminInfo(mInfo));
|
||||||
DeviceAdminUtils.getUserIdFromDeviceAdminInfo(mInfo));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Drawable getIcon() {
|
public Drawable getIcon() {
|
||||||
@@ -79,16 +79,25 @@ class DeviceAdminListItem implements Comparable<DeviceAdminListItem> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
return !mDPM.isRemovingAdmin(mInfo.getComponent(),
|
return !mDPM.isRemovingAdmin(mInfo.getComponent(), getUserIdFromDeviceAdminInfo(mInfo));
|
||||||
DeviceAdminUtils.getUserIdFromDeviceAdminInfo(mInfo));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserHandle getUser() {
|
public UserHandle getUser() {
|
||||||
return new UserHandle(DeviceAdminUtils.getUserIdFromDeviceAdminInfo(mInfo));
|
return new UserHandle(getUserIdFromDeviceAdminInfo(mInfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Intent getLaunchIntent(Context context) {
|
public Intent getLaunchIntent(Context context) {
|
||||||
return new Intent(context, DeviceAdminAdd.class)
|
return new Intent(context, DeviceAdminAdd.class)
|
||||||
.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mInfo.getComponent());
|
.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mInfo.getComponent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts the user id from a device admin info object.
|
||||||
|
*
|
||||||
|
* @param adminInfo the device administrator info.
|
||||||
|
* @return identifier of the user associated with the device admin.
|
||||||
|
*/
|
||||||
|
private static int getUserIdFromDeviceAdminInfo(DeviceAdminInfo adminInfo) {
|
||||||
|
return UserHandle.getUserId(adminInfo.getActivityInfo().applicationInfo.uid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -53,6 +53,9 @@ import com.android.settingslib.core.lifecycle.events.OnStop;
|
|||||||
import com.android.settingslib.widget.FooterPreference;
|
import com.android.settingslib.widget.FooterPreference;
|
||||||
import com.android.settingslib.widget.FooterPreferenceMixinCompat;
|
import com.android.settingslib.widget.FooterPreferenceMixinCompat;
|
||||||
|
|
||||||
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -249,8 +252,7 @@ public class DeviceAdminListPreferenceController extends BasePreferenceControlle
|
|||||||
Log.w(TAG, "Unable to load component: " + activeAdmin);
|
Log.w(TAG, "Unable to load component: " + activeAdmin);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final DeviceAdminInfo deviceAdminInfo = DeviceAdminUtils.createDeviceAdminInfo(
|
final DeviceAdminInfo deviceAdminInfo = createDeviceAdminInfo(mContext, ai);
|
||||||
mContext, ai);
|
|
||||||
if (deviceAdminInfo == null) {
|
if (deviceAdminInfo == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -286,7 +288,7 @@ public class DeviceAdminListPreferenceController extends BasePreferenceControlle
|
|||||||
&& alreadyAddedComponents.contains(riComponentName)) {
|
&& alreadyAddedComponents.contains(riComponentName)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
DeviceAdminInfo deviceAdminInfo = DeviceAdminUtils.createDeviceAdminInfo(
|
DeviceAdminInfo deviceAdminInfo = createDeviceAdminInfo(
|
||||||
mContext, resolveInfo.activityInfo);
|
mContext, resolveInfo.activityInfo);
|
||||||
// add only visible ones (note: active admins are added regardless of visibility)
|
// add only visible ones (note: active admins are added regardless of visibility)
|
||||||
if (deviceAdminInfo != null && deviceAdminInfo.isVisible()) {
|
if (deviceAdminInfo != null && deviceAdminInfo.isVisible()) {
|
||||||
@@ -297,4 +299,20 @@ public class DeviceAdminListPreferenceController extends BasePreferenceControlle
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a device admin info object for the resolved intent that points to the component of
|
||||||
|
* the device admin.
|
||||||
|
*
|
||||||
|
* @param ai ActivityInfo for the admin component.
|
||||||
|
* @return new {@link DeviceAdminInfo} object or null if there was an error.
|
||||||
|
*/
|
||||||
|
private static DeviceAdminInfo createDeviceAdminInfo(Context context, ActivityInfo ai) {
|
||||||
|
try {
|
||||||
|
return new DeviceAdminInfo(context, ai);
|
||||||
|
} catch (XmlPullParserException | IOException e) {
|
||||||
|
Log.w(TAG, "Skipping " + ai, e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,58 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2018 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.android.settings.applications.specialaccess.deviceadmin;
|
|
||||||
|
|
||||||
import android.app.admin.DeviceAdminInfo;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.pm.ActivityInfo;
|
|
||||||
import android.os.UserHandle;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class DeviceAdminUtils {
|
|
||||||
|
|
||||||
private static final String TAG = "DeviceAdminUtils";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a device admin info object for the resolved intent that points to the component of
|
|
||||||
* the device admin.
|
|
||||||
*
|
|
||||||
* @param ai ActivityInfo for the admin component.
|
|
||||||
* @return new {@link DeviceAdminInfo} object or null if there was an error.
|
|
||||||
*/
|
|
||||||
public static DeviceAdminInfo createDeviceAdminInfo(Context context, ActivityInfo ai) {
|
|
||||||
try {
|
|
||||||
return new DeviceAdminInfo(context, ai);
|
|
||||||
} catch (XmlPullParserException | IOException e) {
|
|
||||||
Log.w(TAG, "Skipping " + ai, e);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extracts the user id from a device admin info object.
|
|
||||||
*
|
|
||||||
* @param adminInfo the device administrator info.
|
|
||||||
* @return identifier of the user associated with the device admin.
|
|
||||||
*/
|
|
||||||
public static int getUserIdFromDeviceAdminInfo(DeviceAdminInfo adminInfo) {
|
|
||||||
return UserHandle.getUserId(adminInfo.getActivityInfo().applicationInfo.uid);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -67,7 +67,7 @@ public class DeviceAdminListItemTest {
|
|||||||
|
|
||||||
DeviceAdminListItem item = new DeviceAdminListItem(mContext, mDeviceAdminInfo);
|
DeviceAdminListItem item = new DeviceAdminListItem(mContext, mDeviceAdminInfo);
|
||||||
|
|
||||||
assertThat(item.getKey()).isEqualTo(cn.flattenToShortString());
|
assertThat(item.getKey()).isEqualTo("0@" + cn.flattenToShortString());
|
||||||
assertThat(item.getName()).isEqualTo(label);
|
assertThat(item.getName()).isEqualTo(label);
|
||||||
assertThat(item.getDescription()).isEqualTo(description);
|
assertThat(item.getDescription()).isEqualTo(description);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user