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