summaryrefslogtreecommitdiffstats
path: root/services/devicepolicy
diff options
context:
space:
mode:
authorRubin Xu <rubinxu@google.com>2015-03-10 17:52:37 +0000
committerRubin Xu <rubinxu@google.com>2015-04-14 09:34:03 +0100
commit8027a4ffc285ba39df3a262abfff1cfdd6dd31db (patch)
treea2cc9982c0099d36fb93fcd36c2ecf758eb5ed1d /services/devicepolicy
parent8cc578c37b3f8f4f97e96617fda6538852d71628 (diff)
downloadframeworks_base-8027a4ffc285ba39df3a262abfff1cfdd6dd31db.zip
frameworks_base-8027a4ffc285ba39df3a262abfff1cfdd6dd31db.tar.gz
frameworks_base-8027a4ffc285ba39df3a262abfff1cfdd6dd31db.tar.bz2
Add setOtaPolicy/getOtaPolicy API in DPMS
Allow device owners to set OTA policy for automatically accept/postpone incoming OTA system updates. This class only provides the setting and getting of OTA policy, the actual OTA subsystem should handle and respect the policy stored here. Bug: 19650524 Change-Id: I9b64949fab42097429b7da649039c13f42c10fd1
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 3677132..3ba72ac7 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -5872,4 +5872,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();
+ }
+ }
}