Home | History | Annotate | Download | only in implicitapp
      1 /*
      2  * Copyright (C) 2017 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.cts.implicitapp;
     18 
     19 import android.app.Activity;
     20 import android.content.Intent;
     21 import android.content.pm.PackageInfo;
     22 import android.content.pm.ResolveInfo;
     23 import android.content.pm.PackageManager.NameNotFoundException;
     24 import android.net.Uri;
     25 import android.os.Bundle;
     26 import android.util.Log;
     27 
     28 import com.android.cts.util.TestResult;
     29 
     30 import java.io.PrintWriter;
     31 import java.io.StringWriter;
     32 import java.util.List;
     33 
     34 public class ImplicitActivity extends Activity {
     35     @Override
     36     protected void onCreate(Bundle savedInstanceState) {
     37         super.onCreate(savedInstanceState);
     38 
     39         boolean canAccessInstantApp = false;
     40         String exception = null;
     41         try {
     42             canAccessInstantApp = tryAccessingInstantApp();
     43         } catch (Throwable t) {
     44             exception = t.getClass().getName();
     45         }
     46 
     47         TestResult.getBuilder()
     48                 .setPackageName("com.android.cts.implicitapp")
     49                 .setComponentName("ImplicitActivity")
     50                 .setStatus("PASS")
     51                 .setException(exception)
     52                 .setEphemeralPackageInfoExposed(canAccessInstantApp)
     53                 .build()
     54                 .broadcast(this);
     55         finish();
     56     }
     57 
     58     private boolean tryAccessingInstantApp() throws NameNotFoundException {
     59         final PackageInfo info = getPackageManager()
     60                 .getPackageInfo("com.android.cts.ephemeralapp1", 0 /*flags*/);
     61         return (info != null);
     62     }
     63 }
     64