1 /* 2 * Copyright (C) 2021 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 package com.android.tradefed.command; 17 18 import com.android.tradefed.util.ResourceUtil; 19 20 import java.io.File; 21 22 /** Detects and returns whether this is a local developer running Tradefed. */ 23 public class LocalDeveloper { 24 25 private static final String CLIENT_ID_FILE = "/local_dev/client_id_file.json"; 26 27 /** Returns error code 0 for a local developer, and non-zero for not local. */ main(final String[] mainArgs)28 public static void main(final String[] mainArgs) { 29 String localClientEnv = System.getenv("LOCAL_CLIENT_FILE"); 30 File clientFile = null; 31 // If we are explicitly given a local client file, use it. 32 if (localClientEnv == null) { 33 System.exit(1); 34 } 35 clientFile = new File(localClientEnv); 36 if (clientFile.exists()) { 37 System.exit(0); 38 } 39 // If the bundled client file exists 40 boolean res = ResourceUtil.extractResourceAsFile(CLIENT_ID_FILE, clientFile); 41 if (res) { 42 System.exit(0); 43 } 44 // Delete the tmp file in case of issue 45 clientFile.delete(); 46 System.exit(1); 47 } 48 } 49