Merge changes I4859c8db,I7643024d
* changes: Add the TZInfo updater and relevant intent. Fix ConfigUpdater for binary files.
This commit is contained in:
committed by
Android (Google) Code Review
commit
d4b1d9cf9c
@@ -2290,6 +2290,12 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</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"
|
<receiver android:name="com.android.server.MasterClearReceiver"
|
||||||
android:permission="android.permission.MASTER_CLEAR"
|
android:permission="android.permission.MASTER_CLEAR"
|
||||||
android:priority="100" >
|
android:priority="100" >
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ public class ConfigUpdateInstallReceiver extends BroadcastReceiver {
|
|||||||
// get the certificate from Settings.Secure
|
// get the certificate from Settings.Secure
|
||||||
X509Certificate cert = getCert(context.getContentResolver());
|
X509Certificate cert = getCert(context.getContentResolver());
|
||||||
// get the content path from the extras
|
// get the content path from the extras
|
||||||
String altContent = getAltContent(intent);
|
byte[] altContent = getAltContent(intent);
|
||||||
// get the version from the extras
|
// get the version from the extras
|
||||||
int altVersion = getVersionFromIntent(intent);
|
int altVersion = getVersionFromIntent(intent);
|
||||||
// get the previous value from the extras
|
// get the previous value from the extras
|
||||||
@@ -172,28 +172,26 @@ public class ConfigUpdateInstallReceiver extends BroadcastReceiver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getAltContent(Intent i) throws IOException {
|
private byte[] getAltContent(Intent i) throws IOException {
|
||||||
String contents = IoUtils.readFileAsString(getContentFromIntent(i));
|
return IoUtils.readFileAsByteArray(getContentFromIntent(i));
|
||||||
return contents.trim();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getCurrentContent() {
|
private byte[] getCurrentContent() {
|
||||||
try {
|
try {
|
||||||
return IoUtils.readFileAsString(updateContent.getCanonicalPath()).trim();
|
return IoUtils.readFileAsByteArray(updateContent.getCanonicalPath());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Slog.i(TAG, "Failed to read current content, assuming first update!");
|
Slog.i(TAG, "Failed to read current content, assuming first update!");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getCurrentHash(String content) {
|
private static String getCurrentHash(byte[] content) {
|
||||||
if (content == null) {
|
if (content == null) {
|
||||||
return "0";
|
return "0";
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
MessageDigest dgst = MessageDigest.getInstance("SHA512");
|
MessageDigest dgst = MessageDigest.getInstance("SHA512");
|
||||||
byte[] encoded = content.getBytes();
|
byte[] fingerprint = dgst.digest(content);
|
||||||
byte[] fingerprint = dgst.digest(encoded);
|
|
||||||
return IntegralToString.bytesToHexString(fingerprint, false);
|
return IntegralToString.bytesToHexString(fingerprint, false);
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
throw new AssertionError(e);
|
throw new AssertionError(e);
|
||||||
@@ -213,17 +211,17 @@ public class ConfigUpdateInstallReceiver extends BroadcastReceiver {
|
|||||||
return current.equals(required);
|
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 {
|
String signature, X509Certificate cert) throws Exception {
|
||||||
Signature signer = Signature.getInstance("SHA512withRSA");
|
Signature signer = Signature.getInstance("SHA512withRSA");
|
||||||
signer.initVerify(cert);
|
signer.initVerify(cert);
|
||||||
signer.update(content.getBytes());
|
signer.update(content);
|
||||||
signer.update(Long.toString(version).getBytes());
|
signer.update(Long.toString(version).getBytes());
|
||||||
signer.update(requiredPrevious.getBytes());
|
signer.update(requiredPrevious.getBytes());
|
||||||
return signer.verify(Base64.decode(signature.getBytes(), Base64.DEFAULT));
|
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;
|
FileOutputStream out = null;
|
||||||
File tmp = null;
|
File tmp = null;
|
||||||
try {
|
try {
|
||||||
@@ -240,7 +238,7 @@ public class ConfigUpdateInstallReceiver extends BroadcastReceiver {
|
|||||||
tmp.setReadable(true, false);
|
tmp.setReadable(true, false);
|
||||||
// write to it
|
// write to it
|
||||||
out = new FileOutputStream(tmp);
|
out = new FileOutputStream(tmp);
|
||||||
out.write(content.getBytes());
|
out.write(content);
|
||||||
// sync to disk
|
// sync to disk
|
||||||
out.getFD().sync();
|
out.getFD().sync();
|
||||||
// atomic rename
|
// 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, updateContent, content);
|
||||||
writeUpdate(updateDir, updateVersion, Long.toString(version));
|
writeUpdate(updateDir, updateVersion, Long.toString(version).getBytes());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user