1 /* 2 * Copyright (C) 2019 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.devicepolicy.contentcaptureapp; 18 19 import android.app.Activity; 20 import android.content.BroadcastReceiver; 21 import android.content.Context; 22 import android.content.Intent; 23 import android.content.IntentFilter; 24 import android.os.Bundle; 25 import android.util.Log; 26 import android.view.contentcapture.ContentCaptureManager; 27 28 public class SimpleActivity extends Activity { 29 30 public static final String TAG = SimpleActivity.class.getSimpleName() + "contentcapture"; 31 32 private SimpleActivityReceiver mReceiver; 33 34 private ContentCaptureManager mManager; 35 36 @Override onCreate(Bundle saveInstanceState)37 protected void onCreate(Bundle saveInstanceState) { 38 super.onCreate(saveInstanceState); 39 mReceiver = new SimpleActivityReceiver(); 40 registerReceiver(mReceiver, new IntentFilter(SimpleActivityReceiver.ACTION)); 41 } 42 43 @Override onStart()44 public void onStart() { 45 Log.d(TAG, "onStart(): userId=" + android.os.Process.myUserHandle().getIdentifier()); 46 super.onStart(); 47 mManager = getSystemService(ContentCaptureManager.class); 48 if (mManager == null) { 49 Log.e(TAG, "no manager"); 50 finish(); 51 } 52 } 53 54 @Override onDestroy()55 public void onDestroy() { 56 super.onDestroy(); 57 unregisterReceiver(mReceiver); 58 } 59 60 private class SimpleActivityReceiver extends BroadcastReceiver { 61 private static final String ACTION = "SimpleActivityReceiver"; 62 63 @Override onReceive(Context context, Intent intent)64 public void onReceive(Context context, Intent intent) { 65 final Intent broadcastIntent = new Intent() 66 .setAction("ContentCaptureActivityReceiver") 67 .putExtra("enabled", mManager.isContentCaptureEnabled()); 68 sendBroadcast(broadcastIntent); 69 } 70 } 71 } 72