am d4b1d9cf: Merge changes I4859c8db,I7643024d

# Via Android (Google) Code Review (1) and Geremy Condra (1)
* commit 'd4b1d9cf9cee4bd4f234e30069996dc7e449f0e7':
  Add the TZInfo updater and relevant intent.
  Fix ConfigUpdater for binary files.
This commit is contained in:
Geremy Condra
2013-01-31 22:58:55 -08:00
committed by Android Git Automerger
3 changed files with 53 additions and 15 deletions

View File

@@ -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" >

View File

@@ -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());
}
}

View File

@@ -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);
}
}