summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/res/AndroidManifest.xml6
-rw-r--r--services/java/com/android/server/updates/ConfigUpdateInstallReceiver.java28
-rw-r--r--services/java/com/android/server/updates/TZInfoInstallReceiver.java34
3 files changed, 53 insertions, 15 deletions
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index 692c17cd6f70..e5aca4848407 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -2290,6 +2290,12 @@
</intent-filter>
</receiver>
+ <receiver android:name="com.android.server.updates.TZInfoInstallReceiver" >
+ <intent-filter>
+ <action android:name="android.intent.action.UPDATE_TZINFO" />
+ </intent-filter>
+ </receiver>
+
<receiver android:name="com.android.server.MasterClearReceiver"
android:permission="android.permission.MASTER_CLEAR"
android:priority="100" >
diff --git a/services/java/com/android/server/updates/ConfigUpdateInstallReceiver.java b/services/java/com/android/server/updates/ConfigUpdateInstallReceiver.java
index 4480151b21e6..b06531018421 100644
--- a/services/java/com/android/server/updates/ConfigUpdateInstallReceiver.java
+++ b/services/java/com/android/server/updates/ConfigUpdateInstallReceiver.java
@@ -77,7 +77,7 @@ public class ConfigUpdateInstallReceiver extends BroadcastReceiver {
// get the certificate from Settings.Secure
X509Certificate cert = getCert(context.getContentResolver());
// get the content path from the extras
- String altContent = getAltContent(intent);
+ byte[] altContent = getAltContent(intent);
// get the version from the extras
int altVersion = getVersionFromIntent(intent);
// get the previous value from the extras
@@ -172,28 +172,26 @@ public class ConfigUpdateInstallReceiver extends BroadcastReceiver {
}
}
- private String getAltContent(Intent i) throws IOException {
- String contents = IoUtils.readFileAsString(getContentFromIntent(i));
- return contents.trim();
+ private byte[] getAltContent(Intent i) throws IOException {
+ return IoUtils.readFileAsByteArray(getContentFromIntent(i));
}
- private String getCurrentContent() {
+ private byte[] getCurrentContent() {
try {
- return IoUtils.readFileAsString(updateContent.getCanonicalPath()).trim();
+ return IoUtils.readFileAsByteArray(updateContent.getCanonicalPath());
} catch (IOException e) {
Slog.i(TAG, "Failed to read current content, assuming first update!");
return null;
}
}
- private static String getCurrentHash(String content) {
+ private static String getCurrentHash(byte[] content) {
if (content == null) {
return "0";
}
try {
MessageDigest dgst = MessageDigest.getInstance("SHA512");
- byte[] encoded = content.getBytes();
- byte[] fingerprint = dgst.digest(encoded);
+ byte[] fingerprint = dgst.digest(content);
return IntegralToString.bytesToHexString(fingerprint, false);
} catch (NoSuchAlgorithmException e) {
throw new AssertionError(e);
@@ -213,17 +211,17 @@ public class ConfigUpdateInstallReceiver extends BroadcastReceiver {
return current.equals(required);
}
- private boolean verifySignature(String content, int version, String requiredPrevious,
+ private boolean verifySignature(byte[] content, int version, String requiredPrevious,
String signature, X509Certificate cert) throws Exception {
Signature signer = Signature.getInstance("SHA512withRSA");
signer.initVerify(cert);
- signer.update(content.getBytes());
+ signer.update(content);
signer.update(Long.toString(version).getBytes());
signer.update(requiredPrevious.getBytes());
return signer.verify(Base64.decode(signature.getBytes(), Base64.DEFAULT));
}
- private void writeUpdate(File dir, File file, String content) throws IOException {
+ private void writeUpdate(File dir, File file, byte[] content) throws IOException {
FileOutputStream out = null;
File tmp = null;
try {
@@ -240,7 +238,7 @@ public class ConfigUpdateInstallReceiver extends BroadcastReceiver {
tmp.setReadable(true, false);
// write to it
out = new FileOutputStream(tmp);
- out.write(content.getBytes());
+ out.write(content);
// sync to disk
out.getFD().sync();
// atomic rename
@@ -255,8 +253,8 @@ public class ConfigUpdateInstallReceiver extends BroadcastReceiver {
}
}
- private void install(String content, int version) throws IOException {
+ protected void install(byte[] content, int version) throws IOException {
writeUpdate(updateDir, updateContent, content);
- writeUpdate(updateDir, updateVersion, Long.toString(version));
+ writeUpdate(updateDir, updateVersion, Long.toString(version).getBytes());
}
}
diff --git a/services/java/com/android/server/updates/TZInfoInstallReceiver.java b/services/java/com/android/server/updates/TZInfoInstallReceiver.java
new file mode 100644
index 000000000000..83adbdbd7799
--- /dev/null
+++ b/services/java/com/android/server/updates/TZInfoInstallReceiver.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2013 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.server.updates;
+
+import android.util.Base64;
+import android.util.Slog;
+
+import java.io.IOException;
+
+public class TZInfoInstallReceiver extends ConfigUpdateInstallReceiver {
+
+ public TZInfoInstallReceiver() {
+ super("/data/misc/zoneinfo/", "tzdata", "metadata/", "version");
+ }
+
+ @Override
+ protected void install(byte[] encodedContent, int version) throws IOException {
+ super.install(Base64.decode(encodedContent, Base64.DEFAULT), version);
+ }
+}