1 /* 2 * Copyright (C) 2020 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 android.mediaprovidertranscode.cts.testapp; 18 19 import static android.mediaprovidertranscode.cts.TranscodeTestConstants.INTENT_EXTRA_CALLING_PKG; 20 import static android.mediaprovidertranscode.cts.TranscodeTestConstants.INTENT_EXTRA_PATH; 21 import static android.mediaprovidertranscode.cts.TranscodeTestConstants.OPEN_FILE_QUERY; 22 import static android.mediaprovidertranscode.cts.TranscodeTestConstants.INTENT_QUERY_TYPE; 23 24 import android.app.Activity; 25 import android.content.Intent; 26 import android.net.Uri; 27 import android.os.Bundle; 28 29 import androidx.core.content.FileProvider; 30 31 import java.io.File; 32 33 /** 34 * Helper app for TranscodeTest. 35 * 36 * <p>Used to perform TranscodeTest functions as a different app. Based on the Query type 37 * app can perform different functions and send the result back to host app. 38 */ 39 public class TranscodeTestHelper extends Activity { 40 private static final String TAG = "TranscodeTestHelper"; 41 42 @Override onCreate(Bundle savedInstanceState)43 public void onCreate(Bundle savedInstanceState) { 44 super.onCreate(savedInstanceState); 45 String queryType = getIntent().getStringExtra(INTENT_QUERY_TYPE); 46 if (!OPEN_FILE_QUERY.equals(queryType)) { 47 throw new IllegalStateException( 48 "Unknown query received from launcher app: " + queryType); 49 } 50 51 final File file = new File(getIntent().getStringExtra(INTENT_EXTRA_PATH)); 52 Uri contentUri = FileProvider.getUriForFile(this, getPackageName(), file); 53 54 final Intent intent = new Intent(queryType); 55 intent.putExtra(queryType, contentUri); 56 57 // Grant permission to the calling package 58 getApplicationContext().grantUriPermission(getIntent().getStringExtra( 59 INTENT_EXTRA_CALLING_PKG), 60 contentUri, Intent.FLAG_GRANT_READ_URI_PERMISSION 61 | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); 62 sendBroadcast(intent); 63 } 64 } 65