Home | History | Annotate | Download | only in testing
      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 public class TransportData {
     24     // No constants since new Intent() can't be called in static context because of Robolectric
     25     public static TransportData backupTransport() {
     26         return new TransportData(
     27                 "com.google.android.gms/.backup.BackupTransportService",
     28                 "com.google.android.gms/.backup.BackupTransportService",
     29                 "com.google.android.gms.backup.BackupTransportService",
     30                 new Intent(),
     31                 "user (at) gmail.com",
     32                 new Intent(),
     33                 "Google Account");
     34     }
     35 
     36     public static TransportData d2dTransport() {
     37         return new TransportData(
     38                 "com.google.android.gms/.backup.migrate.service.D2dTransport",
     39                 "com.google.android.gms/.backup.component.D2dTransportService",
     40                 "d2dMigrateTransport",
     41                 null,
     42                 "Moving data to new device",
     43                 null,
     44                 "");
     45     }
     46 
     47     public static TransportData localTransport() {
     48         return new TransportData(
     49                 "android/com.android.internal.backup.LocalTransport",
     50                 "android/com.android.internal.backup.LocalTransportService",
     51                 "com.android.internal.backup.LocalTransport",
     52                 null,
     53                 "Backing up to debug-only private cache",
     54                 null,
     55                 "");
     56     }
     57 
     58     public static TransportData genericTransport(String packageName, String className) {
     59         return new TransportData(
     60                 packageName + "/." + className,
     61                 packageName + "/." + className + "Service",
     62                 packageName + "." + className,
     63                 new Intent(),
     64                 "currentDestinationString",
     65                 new Intent(),
     66                 "dataManagementLabel");
     67     }
     68 
     69     @TransportTestUtils.TransportStatus
     70     public int transportStatus;
     71     public final String transportName;
     72     private final String transportComponentShort;
     73     @Nullable
     74     public String transportDirName;
     75     @Nullable public Intent configurationIntent;
     76     @Nullable public String currentDestinationString;
     77     @Nullable public Intent dataManagementIntent;
     78     @Nullable public String dataManagementLabel;
     79 
     80     private TransportData(
     81             @TransportTestUtils.TransportStatus int transportStatus,
     82             String transportName,
     83             String transportComponentShort,
     84             String transportDirName,
     85             Intent configurationIntent,
     86             String currentDestinationString,
     87             Intent dataManagementIntent,
     88             String 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 
     99     public TransportData(
    100             String transportName,
    101             String transportComponentShort,
    102             String transportDirName,
    103             Intent configurationIntent,
    104             String currentDestinationString,
    105             Intent dataManagementIntent,
    106             String dataManagementLabel) {
    107         this(
    108                 TransportTestUtils.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      */
    122     public ComponentName getTransportComponent() {
    123         return ComponentName.unflattenFromString(transportComponentShort);
    124     }
    125 
    126     public TransportData unavailable() {
    127         return new TransportData(
    128                 TransportTestUtils.TransportStatus.REGISTERED_UNAVAILABLE,
    129                 transportName,
    130                 transportComponentShort,
    131                 transportDirName,
    132                 configurationIntent,
    133                 currentDestinationString,
    134                 dataManagementIntent,
    135                 dataManagementLabel);
    136     }
    137 
    138     public TransportData unregistered() {
    139         return new TransportData(
    140                 TransportTestUtils.TransportStatus.UNREGISTERED,
    141                 transportName,
    142                 transportComponentShort,
    143                 transportDirName,
    144                 configurationIntent,
    145                 currentDestinationString,
    146                 dataManagementIntent,
    147                 dataManagementLabel);
    148     }
    149 }
    150