Merge "Backport of backup transport whitelist" into mnc-dev

am: 2cfc6baa22

* commit '2cfc6baa2286a256585a7fb6295f9b66ff641726':
  Backport of backup transport whitelist

Change-Id: I73dff5d354cd5f26a7f2e68e16f8dd798d610fd3
This commit is contained in:
Christopher Tate
2016-05-25 22:45:49 +00:00
committed by android-build-merger
2 changed files with 51 additions and 7 deletions

View File

@@ -80,7 +80,9 @@ import android.os.storage.StorageManager;
import android.provider.Settings; import android.provider.Settings;
import android.system.ErrnoException; import android.system.ErrnoException;
import android.system.Os; import android.system.Os;
import android.text.TextUtils;
import android.util.ArrayMap; import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.AtomicFile; import android.util.AtomicFile;
import android.util.EventLog; import android.util.EventLog;
import android.util.Log; import android.util.Log;
@@ -93,6 +95,7 @@ import com.android.internal.backup.IBackupTransport;
import com.android.internal.backup.IObbBackupService; import com.android.internal.backup.IObbBackupService;
import com.android.server.AppWidgetBackupBridge; import com.android.server.AppWidgetBackupBridge;
import com.android.server.EventLogTags; import com.android.server.EventLogTags;
import com.android.server.SystemConfig;
import com.android.server.SystemService; import com.android.server.SystemService;
import com.android.server.backup.PackageManagerBackupAgent.Metadata; import com.android.server.backup.PackageManagerBackupAgent.Metadata;
@@ -300,6 +303,7 @@ public class BackupManagerService {
volatile boolean mClearingData; volatile boolean mClearingData;
// Transport bookkeeping // Transport bookkeeping
final ArraySet<ComponentName> mTransportWhitelist;
final Intent mTransportServiceIntent = new Intent(SERVICE_ACTION_TRANSPORT_HOST); final Intent mTransportServiceIntent = new Intent(SERVICE_ACTION_TRANSPORT_HOST);
final ArrayMap<String,String> mTransportNames final ArrayMap<String,String> mTransportNames
= new ArrayMap<String,String>(); // component name -> registration name = new ArrayMap<String,String>(); // component name -> registration name
@@ -1084,11 +1088,15 @@ public class BackupManagerService {
// Set up our transport options and initialize the default transport // Set up our transport options and initialize the default transport
// TODO: Don't create transports that we don't need to? // TODO: Don't create transports that we don't need to?
mCurrentTransport = Settings.Secure.getString(context.getContentResolver(), SystemConfig systemConfig = SystemConfig.getInstance();
mTransportWhitelist = systemConfig.getBackupTransportWhitelist();
String transport = Settings.Secure.getString(context.getContentResolver(),
Settings.Secure.BACKUP_TRANSPORT); Settings.Secure.BACKUP_TRANSPORT);
if ("".equals(mCurrentTransport)) { if (TextUtils.isEmpty(transport)) {
mCurrentTransport = null; transport = null;
} }
mCurrentTransport = transport;
if (DEBUG) Slog.v(TAG, "Starting with transport " + mCurrentTransport); if (DEBUG) Slog.v(TAG, "Starting with transport " + mCurrentTransport);
// Find all transport hosts and bind to their services // Find all transport hosts and bind to their services
@@ -1099,11 +1107,11 @@ public class BackupManagerService {
} }
if (hosts != null) { if (hosts != null) {
for (int i = 0; i < hosts.size(); i++) { for (int i = 0; i < hosts.size(); i++) {
final ServiceInfo transport = hosts.get(i).serviceInfo; final ServiceInfo transportService = hosts.get(i).serviceInfo;
if (MORE_DEBUG) { if (MORE_DEBUG) {
Slog.v(TAG, " " + transport.packageName + "/" + transport.name); Slog.v(TAG, " " + transportService.packageName + "/" + transportService.name);
} }
tryBindTransport(transport); tryBindTransport(transportService);
} }
} }
@@ -1983,7 +1991,12 @@ public class BackupManagerService {
// Actually bind; presumes that we have already validated the transport service // Actually bind; presumes that we have already validated the transport service
boolean bindTransport(ServiceInfo transport) { boolean bindTransport(ServiceInfo transport) {
ComponentName svcName = new ComponentName(transport.packageName, transport.name); ComponentName svcName = new ComponentName(transport.packageName, transport.name);
if (MORE_DEBUG) { if (!mTransportWhitelist.contains(svcName)) {
Slog.w(TAG, "Proposed transport " + svcName + " not whitelisted; ignoring");
return false;
}
if (DEBUG) {
Slog.i(TAG, "Binding to transport host " + svcName); Slog.i(TAG, "Binding to transport host " + svcName);
} }
Intent intent = new Intent(mTransportServiceIntent); Intent intent = new Intent(mTransportServiceIntent);
@@ -9636,6 +9649,12 @@ if (MORE_DEBUG) Slog.v(TAG, " + got " + nRead + "; now wanting " + (size - soF
+ " (now = " + System.currentTimeMillis() + ')'); + " (now = " + System.currentTimeMillis() + ')');
pw.println(" next scheduled: " + KeyValueBackupJob.nextScheduled()); pw.println(" next scheduled: " + KeyValueBackupJob.nextScheduled());
pw.println("Transport whitelist:");
for (ComponentName transport : mTransportWhitelist) {
pw.print(" ");
pw.println(transport.flattenToShortString());
}
pw.println("Available transports:"); pw.println("Available transports:");
final String[] transports = listAllTransports(); final String[] transports = listAllTransports();
if (transports != null) { if (transports != null) {

View File

@@ -17,6 +17,7 @@
package com.android.server; package com.android.server;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.pm.FeatureInfo; import android.content.pm.FeatureInfo;
import android.os.*; import android.os.*;
import android.os.Process; import android.os.Process;
@@ -99,6 +100,9 @@ public class SystemConfig {
// URL-handling state upon factory reset. // URL-handling state upon factory reset.
final ArraySet<String> mLinkedApps = new ArraySet<>(); final ArraySet<String> mLinkedApps = new ArraySet<>();
// These are the permitted backup transport service components
final ArraySet<ComponentName> mBackupTransportWhitelist = new ArraySet<>();
public static SystemConfig getInstance() { public static SystemConfig getInstance() {
synchronized (SystemConfig.class) { synchronized (SystemConfig.class) {
if (sInstance == null) { if (sInstance == null) {
@@ -144,6 +148,10 @@ public class SystemConfig {
return mLinkedApps; return mLinkedApps;
} }
public ArraySet<ComponentName> getBackupTransportWhitelist() {
return mBackupTransportWhitelist;
}
SystemConfig() { SystemConfig() {
// Read configuration from system // Read configuration from system
readPermissions(Environment.buildPath( readPermissions(Environment.buildPath(
@@ -380,6 +388,23 @@ public class SystemConfig {
mLinkedApps.add(pkgname); mLinkedApps.add(pkgname);
} }
XmlUtils.skipCurrentTag(parser); XmlUtils.skipCurrentTag(parser);
} else if ("backup-transport-whitelisted-service".equals(name)) {
String serviceName = parser.getAttributeValue(null, "service");
if (serviceName == null) {
Slog.w(TAG, "<backup-transport-whitelisted-service> without service in "
+ permFile + " at " + parser.getPositionDescription());
} else {
ComponentName cn = ComponentName.unflattenFromString(serviceName);
if (cn == null) {
Slog.w(TAG,
"<backup-transport-whitelisted-service> with invalid service name "
+ serviceName + " in "+ permFile
+ " at " + parser.getPositionDescription());
} else {
mBackupTransportWhitelist.add(cn);
}
}
XmlUtils.skipCurrentTag(parser);
} else { } else {
XmlUtils.skipCurrentTag(parser); XmlUtils.skipCurrentTag(parser);