Starting March 27, 2025, we recommend using android-latest-release instead of aosp-main to build and contribute to AOSP. For more information, see Changes to AOSP.
         
       
     
  
  
  
  
  
    
    
      
    
    
      
      Stay organized with collections
    
    
      
      Save and categorize content based on your preferences.
    
  
  
    
  
  
  
  
    
  
  
    
    
  
  
GoogleApiClientUtil
  public
  
  
  
  class
  GoogleApiClientUtil
  
    extends Object
  
  
  
  
  
  
  
    
    | java.lang.Object | 
  
  
    
      | ↳ | com.android.tradefed.util.GoogleApiClientUtil | 
  
  
    
  Utils for create Google API client. 
Summary
| Fields | 
|---|
  
    | 
    public
    static
    final
    String | APP_NAME
      
    
 | 
  
| Public methods | 
|---|
  
  
  
    | 
        
        
        static
        
        
        HttpRequestInitializer | 
      configureRetryStrategy(HttpRequestInitializer initializer)
      Setup a retry strategy for the provided HttpRequestInitializer.
        
    
 | 
  
  
  
  
    | 
        
        
        static
        
        
        Credential | 
      createCredential( scopes, Boolean useCredentialFactory, File primaryKeyFile, String hostOptionKeyFileName, File... backupKeyFiles)
      Try to create credential with different key files or from local host.
        
    
 | 
  
  
  
  
    | 
        
        
        static
        
        
        Credential | 
      createCredential( scopes, File primaryKeyFile, String hostOptionKeyFileName, File... backupKeyFiles)
      Try to create credential with different key files or from local host.
        
    
 | 
  
  
  
  
    | 
        
        
        static
        
        
        Credential | 
      createCredentialFromJsonKeyFile(File file,  scopes)
      Create credential from json key file.
        
    
 | 
  
  
  
  
    | 
        
        
        static
        
        
        Credential | 
      createCredentialFromP12File(String serviceAccount, File keyFile,  scopes)
      
      This method is deprecated.
    It's better to use json key file, since p12 is deprecated by Google App Engine.
     And json key file have more information.
        
    
 | 
  
  
  
  
    | 
        
        
        static
        
        
        HttpRequestInitializer | 
      setHttpTimeout(HttpRequestInitializer requestInitializer, int connectTimeout, int readTimeout)
       | 
  
Fields
    APP_NAME
    
      
  
      
  
    
public static final String APP_NAME
    
    
    
  
    
 
Public constructors
    GoogleApiClientUtil
    
public GoogleApiClientUtil ()
    
    
    
  
 
Public methods
    
    
public static HttpRequestInitializer configureRetryStrategy (HttpRequestInitializer initializer)
    
    
    
  Setup a retry strategy for the provided HttpRequestInitializer. In case of server errors
 requests will be automatically retried with an exponential backoff.
    
    | Parameters | 
|---|
      
        | initializer | HttpRequestInitializer: - an initializer which will setup a retry strategy. | 
    
    
      | Returns | 
|---|
      
        | HttpRequestInitializer | an initializer that will retry failed requests automatically. | 
    
 
    createCredential
    
public static Credential createCredential ( scopes, 
                Boolean useCredentialFactory, 
                File primaryKeyFile, 
                String hostOptionKeyFileName, 
                File... backupKeyFiles)
    
    
    
  Try to create credential with different key files or from local host.
 
1. Use ICredentialFactory if useCredentialFactory is true and a ICredentialFactory is configured. If primaryKeyFile is set, try to use it to create
 credential. 2. Try to get corresponding key files from HostOptions. 3. Try to use
 backup key files. 4. Use local default credential.
    
    | Parameters | 
|---|
      
        | scopes | : scopes for the credential. | 
      
        | useCredentialFactory | Boolean: use credential factory if it's configured. | 
      
        | primaryKeyFile | File: the primary json key file; it can be null. | 
      
        | hostOptionKeyFileName | String:HostOptions'service-account-json-key-file option's key;
     it can be null. | 
      
        | backupKeyFiles | File: backup key files. | 
    
    
      
  
 
    createCredential
    
public static Credential createCredential ( scopes, 
                File primaryKeyFile, 
                String hostOptionKeyFileName, 
                File... backupKeyFiles)
    
    
    
  Try to create credential with different key files or from local host.
 
1. If primaryKeyFile is set, try to use it to create credential. 2. Try to get
 corresponding key files from HostOptions. 3. Try to use backup key files. 4. Use
 local default credential.
    
    | Parameters | 
|---|
      
        | scopes | : scopes for the credential. | 
      
        | primaryKeyFile | File: the primary json key file; it can be null. | 
      
        | hostOptionKeyFileName | String:HostOptions'service-account-json-key-file option's key;
     it can be null. | 
      
        | backupKeyFiles | File: backup key files. | 
    
    
      
  
 
    createCredentialFromJsonKeyFile
    
public static Credential createCredentialFromJsonKeyFile (File file, 
                 scopes)
    
    
    
  Create credential from json key file.
    
    | Parameters | 
|---|
      
        | file | File: is the p12 key file | 
      
        | scopes | : is the API's scope. | 
    
    
      
      | Throws | 
|---|
        
          |  | FileNotFoundException | 
        
          |  | IOException | 
      
  
 
    createCredentialFromP12File
    
public static Credential createCredentialFromP12File (String serviceAccount, 
                File keyFile, 
                 scopes)
    
    
    
  
      This method is deprecated.
    It's better to use json key file, since p12 is deprecated by Google App Engine.
     And json key file have more information.
  
  Create credential from p12 file for service account.
    
    | Parameters | 
|---|
      
        | serviceAccount | String: is the service account | 
      
        | keyFile | File: is the p12 key file | 
      
        | scopes | : is the API's scope. | 
    
    
      
      | Throws | 
|---|
        
          |  | GeneralSecurityException | 
      
  
 
    setHttpTimeout
    
public static HttpRequestInitializer setHttpTimeout (HttpRequestInitializer requestInitializer, 
                int connectTimeout, 
                int readTimeout)
    
    
    
  
    
    | Parameters | 
|---|
      
        | requestInitializer | HttpRequestInitializer: aHttpRequestInitializer, normally it'sCredential. | 
      
        | connectTimeout | int: connect timeout in milliseconds. | 
      
        | readTimeout | int: read timeout in milliseconds. | 
    
    
 
 
 
  
  
 
  
    
    
      
    
    
  
       
    
    
  
  
  Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
  Last updated 2022-08-03 UTC.
  
  
  
    
      [[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2022-08-03 UTC."],[],[]]