8080import android .provider .Settings ;
8181import android .system .ErrnoException ;
8282import android .system .Os ;
83+ import android .text .TextUtils ;
8384import android .util .ArrayMap ;
85+ import android .util .ArraySet ;
8486import android .util .AtomicFile ;
8587import android .util .EventLog ;
8688import android .util .Log ;
9395import com .android .internal .backup .IObbBackupService ;
9496import com .android .server .AppWidgetBackupBridge ;
9597import com .android .server .EventLogTags ;
98+ import com .android .server .SystemConfig ;
9699import com .android .server .SystemService ;
97100import com .android .server .backup .PackageManagerBackupAgent .Metadata ;
98101
@@ -300,6 +303,7 @@ public String toString() {
300303 volatile boolean mClearingData ;
301304
302305 // Transport bookkeeping
306+ final ArraySet <ComponentName > mTransportWhitelist ;
303307 final Intent mTransportServiceIntent = new Intent (SERVICE_ACTION_TRANSPORT_HOST );
304308 final ArrayMap <String ,String > mTransportNames
305309 = new ArrayMap <String ,String >(); // component name -> registration name
@@ -1084,11 +1088,15 @@ public BackupManagerService(Context context, Trampoline parent) {
10841088
10851089 // Set up our transport options and initialize the default transport
10861090 // TODO: Don't create transports that we don't need to?
1087- mCurrentTransport = Settings .Secure .getString (context .getContentResolver (),
1091+ SystemConfig systemConfig = SystemConfig .getInstance ();
1092+ mTransportWhitelist = systemConfig .getBackupTransportWhitelist ();
1093+
1094+ String transport = Settings .Secure .getString (context .getContentResolver (),
10881095 Settings .Secure .BACKUP_TRANSPORT );
1089- if ("" . equals ( mCurrentTransport )) {
1090- mCurrentTransport = null ;
1096+ if (TextUtils . isEmpty ( transport )) {
1097+ transport = null ;
10911098 }
1099+ mCurrentTransport = transport ;
10921100 if (DEBUG ) Slog .v (TAG , "Starting with transport " + mCurrentTransport );
10931101
10941102 // Find all transport hosts and bind to their services
@@ -1099,11 +1107,11 @@ public BackupManagerService(Context context, Trampoline parent) {
10991107 }
11001108 if (hosts != null ) {
11011109 for (int i = 0 ; i < hosts .size (); i ++) {
1102- final ServiceInfo transport = hosts .get (i ).serviceInfo ;
1110+ final ServiceInfo transportService = hosts .get (i ).serviceInfo ;
11031111 if (MORE_DEBUG ) {
1104- Slog .v (TAG , " " + transport .packageName + "/" + transport .name );
1112+ Slog .v (TAG , " " + transportService .packageName + "/" + transportService .name );
11051113 }
1106- tryBindTransport (transport );
1114+ tryBindTransport (transportService );
11071115 }
11081116 }
11091117
@@ -1983,7 +1991,12 @@ boolean tryBindTransport(ServiceInfo info) {
19831991 // Actually bind; presumes that we have already validated the transport service
19841992 boolean bindTransport (ServiceInfo transport ) {
19851993 ComponentName svcName = new ComponentName (transport .packageName , transport .name );
1986- if (MORE_DEBUG ) {
1994+ if (!mTransportWhitelist .contains (svcName )) {
1995+ Slog .w (TAG , "Proposed transport " + svcName + " not whitelisted; ignoring" );
1996+ return false ;
1997+ }
1998+
1999+ if (DEBUG ) {
19872000 Slog .i (TAG , "Binding to transport host " + svcName );
19882001 }
19892002 Intent intent = new Intent (mTransportServiceIntent );
@@ -9636,6 +9649,12 @@ private void dumpInternal(PrintWriter pw) {
96369649 + " (now = " + System .currentTimeMillis () + ')' );
96379650 pw .println (" next scheduled: " + KeyValueBackupJob .nextScheduled ());
96389651
9652+ pw .println ("Transport whitelist:" );
9653+ for (ComponentName transport : mTransportWhitelist ) {
9654+ pw .print (" " );
9655+ pw .println (transport .flattenToShortString ());
9656+ }
9657+
96399658 pw .println ("Available transports:" );
96409659 final String [] transports = listAllTransports ();
96419660 if (transports != null ) {
0 commit comments