Home | History | Annotate | Download | only in managedprofile
      1 /*
      2  * Copyright (C) 2015 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.managedprofile;
     18 
     19 import android.content.Intent;
     20 import android.content.pm.PackageManager;
     21 import android.content.pm.ResolveInfo;
     22 import android.test.AndroidTestCase;
     23 import android.util.Log;
     24 
     25 public class NfcTest extends AndroidTestCase {
     26     private static final String SAMPLE_TEXT = "This is my text to send.";
     27     private static final String TEXT_MIME_TYPE = "text/plain";
     28     private static final String NFC_BEAM_ACTIVITY = "com.android.nfc.BeamShareActivity";
     29 
     30     public void testNfcShareDisabled() throws Exception {
     31         Intent intent = getTextShareIntent();
     32         assertFalse("Nfc beam activity should not be resolved", isNfcBeamActivityResolved(intent));
     33     }
     34 
     35     public void testNfcShareEnabled() throws Exception {
     36         Intent intent = getTextShareIntent();
     37         assertTrue("Nfc beam activity should be resolved", isNfcBeamActivityResolved(intent));
     38     }
     39 
     40     private Intent getTextShareIntent() {
     41         Intent intent = new Intent();
     42         intent.setAction(Intent.ACTION_SEND);
     43         intent.putExtra(Intent.EXTRA_TEXT, SAMPLE_TEXT);
     44         intent.setType(TEXT_MIME_TYPE);
     45         return intent;
     46     }
     47 
     48     private boolean isNfcBeamActivityResolved(Intent intent) {
     49         PackageManager pm = mContext.getPackageManager();
     50         for (ResolveInfo resolveInfo : pm.queryIntentActivities(intent, 0)) {
     51             if (NFC_BEAM_ACTIVITY.equals(resolveInfo.activityInfo.name)) {
     52                 return true;
     53             }
     54         }
     55 
     56         return false;
     57     }
     58 }
     59 
     60