1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 17 package com.android.server.backup.testing; 18 19 import android.annotation.Nullable; 20 import android.content.ComponentName; 21 import android.content.Intent; 22 23 import com.android.server.backup.testing.TransportTestUtils.TransportStatus; 24 25 public class TransportData { 26 // No constants since new Intent() can't be called in static context because of Robolectric backupTransport()27 public static TransportData backupTransport() { 28 return new TransportData( 29 "com.google.android.gms/.backup.BackupTransportService", 30 "com.google.android.gms/.backup.BackupTransportService", 31 "com.google.android.gms.backup.BackupTransportService", 32 new Intent(), 33 "user@gmail.com", 34 new Intent(), 35 "Google Account"); 36 } 37 d2dTransport()38 public static TransportData d2dTransport() { 39 return new TransportData( 40 "com.google.android.gms/.backup.migrate.service.D2dTransport", 41 "com.google.android.gms/.backup.component.D2dTransportService", 42 "d2dMigrateTransport", 43 null, 44 "Moving data to new device", 45 null, 46 ""); 47 } 48 localTransport()49 public static TransportData localTransport() { 50 return new TransportData( 51 "com.android.localtransport/.LocalTransport", 52 "com.android.localtransport/.LocalTransportService", 53 "com.android.localtransport.LocalTransport", 54 null, 55 "Backing up to debug-only private cache", 56 null, 57 ""); 58 } 59 genericTransport(String packageName, String className)60 public static TransportData genericTransport(String packageName, String className) { 61 return new TransportData( 62 packageName + "/." + className, 63 packageName + "/." + className + "Service", 64 packageName + "." + className, 65 new Intent(), 66 "currentDestinationString", 67 new Intent(), 68 "dataManagementLabel"); 69 } 70 71 @TransportStatus public int transportStatus; 72 public final String transportName; 73 private final String transportComponentShort; 74 @Nullable public String transportDirName; 75 @Nullable public Intent configurationIntent; 76 @Nullable public String currentDestinationString; 77 @Nullable public Intent dataManagementIntent; 78 @Nullable public CharSequence dataManagementLabel; 79 TransportData( @ransportStatus int transportStatus, String transportName, String transportComponentShort, String transportDirName, Intent configurationIntent, String currentDestinationString, Intent dataManagementIntent, CharSequence dataManagementLabel)80 private TransportData( 81 @TransportStatus int transportStatus, 82 String transportName, 83 String transportComponentShort, 84 String transportDirName, 85 Intent configurationIntent, 86 String currentDestinationString, 87 Intent dataManagementIntent, 88 CharSequence dataManagementLabel) { 89 this.transportStatus = transportStatus; 90 this.transportName = transportName; 91 this.transportComponentShort = transportComponentShort; 92 this.transportDirName = transportDirName; 93 this.configurationIntent = configurationIntent; 94 this.currentDestinationString = currentDestinationString; 95 this.dataManagementIntent = dataManagementIntent; 96 this.dataManagementLabel = dataManagementLabel; 97 } 98 TransportData( String transportName, String transportComponentShort, String transportDirName, Intent configurationIntent, String currentDestinationString, Intent dataManagementIntent, CharSequence dataManagementLabel)99 public TransportData( 100 String transportName, 101 String transportComponentShort, 102 String transportDirName, 103 Intent configurationIntent, 104 String currentDestinationString, 105 Intent dataManagementIntent, 106 CharSequence dataManagementLabel) { 107 this( 108 TransportStatus.REGISTERED_AVAILABLE, 109 transportName, 110 transportComponentShort, 111 transportDirName, 112 configurationIntent, 113 currentDestinationString, 114 dataManagementIntent, 115 dataManagementLabel); 116 } 117 118 /** 119 * Not field because otherwise we'd have to call ComponentName::new in static context and 120 * Robolectric does not like this. 121 */ getTransportComponent()122 public ComponentName getTransportComponent() { 123 return ComponentName.unflattenFromString(transportComponentShort); 124 } 125 unavailable()126 public TransportData unavailable() { 127 return new TransportData( 128 TransportStatus.REGISTERED_UNAVAILABLE, 129 transportName, 130 transportComponentShort, 131 transportDirName, 132 configurationIntent, 133 currentDestinationString, 134 dataManagementIntent, 135 dataManagementLabel); 136 } 137 unregistered()138 public TransportData unregistered() { 139 return new TransportData( 140 TransportStatus.UNREGISTERED, 141 transportName, 142 transportComponentShort, 143 transportDirName, 144 configurationIntent, 145 currentDestinationString, 146 dataManagementIntent, 147 dataManagementLabel); 148 } 149 } 150