Methods Summary |
---|
void | clearDeviceOwner()
mDeviceOwner = null;
|
static com.android.server.devicepolicy.DeviceOwner | createWithDeviceOwner(java.lang.String packageName, java.lang.String ownerName)Creates an instance of the device owner object with the device owner set.
DeviceOwner owner = new DeviceOwner();
owner.mDeviceOwner = new OwnerInfo(ownerName, packageName);
return owner;
|
static com.android.server.devicepolicy.DeviceOwner | createWithProfileOwner(java.lang.String packageName, java.lang.String ownerName, int userId)
DeviceOwner owner = new DeviceOwner();
owner.mProfileOwners.put(userId, new OwnerInfo(ownerName, packageName));
return owner;
|
static com.android.server.devicepolicy.DeviceOwner | createWithProfileOwner(android.content.ComponentName admin, java.lang.String ownerName, int userId)Creates an instance of the device owner object with the profile owner set.
DeviceOwner owner = new DeviceOwner();
owner.mProfileOwners.put(userId, new OwnerInfo(ownerName, admin));
return owner;
|
private void | finishWrite(java.io.OutputStream stream)
if (fileForWriting != null) {
fileForWriting.finishWrite((FileOutputStream) stream);
}
|
java.lang.String | getDeviceOwnerName()
return mDeviceOwner != null ? mDeviceOwner.name : null;
|
java.lang.String | getDeviceOwnerPackageName()
return mDeviceOwner != null ? mDeviceOwner.packageName : null;
|
android.content.ComponentName | getProfileOwnerComponent(int userId)
OwnerInfo profileOwner = mProfileOwners.get(userId);
return profileOwner != null ? profileOwner.admin : null;
|
java.util.Set | getProfileOwnerKeys()
return mProfileOwners.keySet();
|
java.lang.String | getProfileOwnerName(int userId)
OwnerInfo profileOwner = mProfileOwners.get(userId);
return profileOwner != null ? profileOwner.name : null;
|
java.lang.String | getProfileOwnerPackageName(int userId)
OwnerInfo profileOwner = mProfileOwners.get(userId);
return profileOwner != null ? profileOwner.packageName : null;
|
boolean | hasDeviceOwner()
return mDeviceOwner != null;
|
static boolean | isInstalled(java.lang.String packageName, android.content.pm.PackageManager pm)
try {
PackageInfo pi;
if ((pi = pm.getPackageInfo(packageName, 0)) != null) {
if ((pi.applicationInfo.flags) != 0) {
return true;
}
}
} catch (NameNotFoundException nnfe) {
Slog.w(TAG, "Device Owner package " + packageName + " not installed.");
}
return false;
|
static boolean | isInstalledForUser(java.lang.String packageName, int userHandle)
try {
PackageInfo pi = (AppGlobals.getPackageManager())
.getPackageInfo(packageName, 0, userHandle);
if (pi != null && pi.applicationInfo.flags != 0) {
return true;
}
} catch (RemoteException re) {
throw new RuntimeException("Package manager has died", re);
}
return false;
|
static com.android.server.devicepolicy.DeviceOwner | load()Loads the device owner state from disk.
DeviceOwner owner = new DeviceOwner();
if (new File(Environment.getSystemSecureDirectory(), DEVICE_OWNER_XML).exists()) {
owner.readOwnerFile();
return owner;
} else {
return null;
}
|
private java.io.InputStream | openRead()
if (mInputStreamForTest != null) {
return mInputStreamForTest;
}
return new AtomicFile(new File(Environment.getSystemSecureDirectory(),
DEVICE_OWNER_XML)).openRead();
|
void | readOwnerFile()
try {
InputStream input = openRead();
XmlPullParser parser = Xml.newPullParser();
parser.setInput(input, null);
int type;
while ((type=parser.next()) != XmlPullParser.END_DOCUMENT) {
if (type!=XmlPullParser.START_TAG) {
continue;
}
String tag = parser.getName();
if (tag.equals(TAG_DEVICE_OWNER)) {
String name = parser.getAttributeValue(null, ATTR_NAME);
String packageName = parser.getAttributeValue(null, ATTR_PACKAGE);
mDeviceOwner = new OwnerInfo(name, packageName);
} else if (tag.equals(TAG_PROFILE_OWNER)) {
String profileOwnerPackageName = parser.getAttributeValue(null, ATTR_PACKAGE);
String profileOwnerName = parser.getAttributeValue(null, ATTR_NAME);
String profileOwnerComponentStr =
parser.getAttributeValue(null, ATTR_COMPONENT_NAME);
int userId = Integer.parseInt(parser.getAttributeValue(null, ATTR_USERID));
OwnerInfo profileOwnerInfo = null;
if (profileOwnerComponentStr != null) {
ComponentName admin = ComponentName.unflattenFromString(
profileOwnerComponentStr);
if (admin != null) {
profileOwnerInfo = new OwnerInfo(profileOwnerName, admin);
} else {
// This shouldn't happen but switch from package name -> component name
// might have written bad device owner files. b/17652534
Slog.e(TAG, "Error parsing device-owner file. Bad component name " +
profileOwnerComponentStr);
}
}
if (profileOwnerInfo == null) {
profileOwnerInfo = new OwnerInfo(profileOwnerName, profileOwnerPackageName);
}
mProfileOwners.put(userId, profileOwnerInfo);
} else {
throw new XmlPullParserException(
"Unexpected tag in device owner file: " + tag);
}
}
input.close();
} catch (XmlPullParserException xppe) {
Slog.e(TAG, "Error parsing device-owner file\n" + xppe);
} catch (IOException ioe) {
Slog.e(TAG, "IO Exception when reading device-owner file\n" + ioe);
}
|
void | removeProfileOwner(int userId)
mProfileOwners.remove(userId);
|
void | setDeviceOwner(java.lang.String packageName, java.lang.String ownerName)
mDeviceOwner = new OwnerInfo(ownerName, packageName);
|
void | setProfileOwner(java.lang.String packageName, java.lang.String ownerName, int userId)
mProfileOwners.put(userId, new OwnerInfo(ownerName, packageName));
|
void | setProfileOwner(android.content.ComponentName admin, java.lang.String ownerName, int userId)
mProfileOwners.put(userId, new OwnerInfo(ownerName, admin));
|
private java.io.OutputStream | startWrite()
if (mOutputStreamForTest != null) {
return mOutputStreamForTest;
}
fileForWriting = new AtomicFile(new File(Environment.getSystemSecureDirectory(),
DEVICE_OWNER_XML));
return fileForWriting.startWrite();
|
void | writeOwnerFile()
synchronized (this) {
writeOwnerFileLocked();
}
|
private void | writeOwnerFileLocked()
try {
OutputStream outputStream = startWrite();
XmlSerializer out = new FastXmlSerializer();
out.setOutput(outputStream, "utf-8");
out.startDocument(null, true);
// Write device owner tag
if (mDeviceOwner != null) {
out.startTag(null, TAG_DEVICE_OWNER);
out.attribute(null, ATTR_PACKAGE, mDeviceOwner.packageName);
if (mDeviceOwner.name != null) {
out.attribute(null, ATTR_NAME, mDeviceOwner.name);
}
out.endTag(null, TAG_DEVICE_OWNER);
}
// Write profile owner tags
if (mProfileOwners.size() > 0) {
for (HashMap.Entry<Integer, OwnerInfo> owner : mProfileOwners.entrySet()) {
out.startTag(null, TAG_PROFILE_OWNER);
OwnerInfo ownerInfo = owner.getValue();
out.attribute(null, ATTR_PACKAGE, ownerInfo.packageName);
out.attribute(null, ATTR_NAME, ownerInfo.name);
out.attribute(null, ATTR_USERID, Integer.toString(owner.getKey()));
if (ownerInfo.admin != null) {
out.attribute(null, ATTR_COMPONENT_NAME, ownerInfo.admin.flattenToString());
}
out.endTag(null, TAG_PROFILE_OWNER);
}
}
out.endDocument();
out.flush();
finishWrite(outputStream);
} catch (IOException ioe) {
Slog.e(TAG, "IO Exception when writing device-owner file\n" + ioe);
}
|