summaryrefslogtreecommitdiffstats
path: root/services/devicepolicy
diff options
context:
space:
mode:
authorRubin Xu <rubinxu@google.com>2015-04-14 09:16:27 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-04-14 09:16:28 +0000
commitc9c9f7b40ec77217ce595fd152a505481326dc9a (patch)
tree3005503c6fec2b9f69a3919a4c622cf82dac0cd0 /services/devicepolicy
parent0c606812c5102fd19eda4b3e1ffbc9e61fec6430 (diff)
parent8027a4ffc285ba39df3a262abfff1cfdd6dd31db (diff)
downloadframeworks_base-c9c9f7b40ec77217ce595fd152a505481326dc9a.zip
frameworks_base-c9c9f7b40ec77217ce595fd152a505481326dc9a.tar.gz
frameworks_base-c9c9f7b40ec77217ce595fd152a505481326dc9a.tar.bz2
Merge "Add setOtaPolicy/getOtaPolicy API in DPMS"
Diffstat (limited to 'services/devicepolicy')
-rw-r--r--services/devicepolicy/java/com/android/server/devicepolicy/DeviceOwner.java30
-rw-r--r--services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java22
2 files changed, 52 insertions, 0 deletions
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DeviceOwner.java b/services/devicepolicy/java/com/android/server/devicepolicy/DeviceOwner.java
index c766183..2661643 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DeviceOwner.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DeviceOwner.java
@@ -22,6 +22,7 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Environment;
+import android.os.PersistableBundle;
import android.os.RemoteException;
import android.util.AtomicFile;
import android.util.Slog;
@@ -59,6 +60,7 @@ class DeviceOwner {
private static final String ATTR_PACKAGE = "package";
private static final String ATTR_COMPONENT_NAME = "component";
private static final String ATTR_USERID = "userId";
+ private static final String TAG_OTA_POLICY = "ota-policy";
private AtomicFile fileForWriting;
@@ -75,6 +77,9 @@ class DeviceOwner {
// Internal state for the profile owner packages.
private final HashMap<Integer, OwnerInfo> mProfileOwners = new HashMap<Integer, OwnerInfo>();
+ // Local OTA policy controllable by device owner.
+ private PersistableBundle mOtaPolicy;
+
// Private default constructor.
private DeviceOwner() {
}
@@ -187,6 +192,18 @@ class DeviceOwner {
return mProfileOwners.keySet();
}
+ PersistableBundle getOtaPolicy() {
+ return mOtaPolicy;
+ }
+
+ void setOtaPolicy(PersistableBundle otaPolicy) {
+ mOtaPolicy = otaPolicy;
+ }
+
+ void clearOtaPolicy() {
+ mOtaPolicy = null;
+ }
+
boolean hasDeviceOwner() {
return mDeviceOwner != null;
}
@@ -273,6 +290,8 @@ class DeviceOwner {
profileOwnerInfo = new OwnerInfo(profileOwnerName, profileOwnerPackageName);
}
mProfileOwners.put(userId, profileOwnerInfo);
+ } else if (TAG_OTA_POLICY.equals(tag)) {
+ mOtaPolicy = PersistableBundle.restoreFromXml(parser);
} else {
throw new XmlPullParserException(
"Unexpected tag in device owner file: " + tag);
@@ -338,6 +357,17 @@ class DeviceOwner {
out.endTag(null, TAG_PROFILE_OWNER);
}
}
+
+ // Write OTA policy tag
+ if (mOtaPolicy != null) {
+ out.startTag(null, TAG_OTA_POLICY);
+ try {
+ mOtaPolicy.saveToXml(out);
+ } catch (XmlPullParserException e) {
+ Slog.e(TAG, "Failed to save OTA policy", e);
+ }
+ out.endTag(null, TAG_OTA_POLICY);
+ }
out.endDocument();
out.flush();
finishWrite(outputStream);
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index 317c630..26c7130 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -5926,4 +5926,26 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
}
return admin.info.usesPolicy(DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD);
}
+
+ @Override
+ public void setOtaPolicy(ComponentName who, PersistableBundle policy) {
+ synchronized (this) {
+ getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER);
+ if (policy == null) {
+ mDeviceOwner.clearOtaPolicy();
+ } else {
+ mDeviceOwner.setOtaPolicy(policy);
+ }
+ mDeviceOwner.writeOwnerFile();
+ }
+ mContext.sendBroadcastAsUser(new Intent(DevicePolicyManager.ACTION_OTA_POLICY_CHANGED),
+ UserHandle.OWNER);
+ }
+
+ @Override
+ public PersistableBundle getOtaPolicy() {
+ synchronized (this) {
+ return mDeviceOwner.getOtaPolicy();
+ }
+ }
}