1 /*
2  * Copyright (C) 2010 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.nfc;
18 
19 import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
20 
21 import static com.android.nfc.NfcService.APP_NAME_ENABLING_NFC;
22 
23 import android.app.Activity;
24 import android.app.AlertDialog;
25 import android.content.Intent;
26 import android.os.Bundle;
27 import android.util.Log;
28 import android.view.View;
29 
30 import androidx.annotation.Nullable;
31 
32 public class NfcEnableAllowlistActivity extends Activity implements View.OnClickListener{
33 
34     static final String TAG = "NfcEnableAllowListActivity";
35 
36     @Override
onCreate(@ullable Bundle savedInstanceState)37     protected void onCreate(@Nullable Bundle savedInstanceState) {
38         Intent intent = getIntent();
39         getWindow().addSystemFlags(SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
40         CharSequence appName = intent.getStringExtra(APP_NAME_ENABLING_NFC);
41         String formatString = getString(R.string.title_package_enabling_nfc);
42         AlertDialog mAlertDialog = new AlertDialog.Builder(this, R.style.DialogAlertDayNight)
43                 .setTitle(String.format(formatString, appName))
44                 .setNegativeButton(R.string.enable_nfc_no, null)
45                 .setPositiveButton(R.string.enable_nfc_yes, null)
46                 .create();
47 
48         mAlertDialog.show();
49         super.onCreate(savedInstanceState);
50         mAlertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(this);
51         mAlertDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener(
52                 v -> {
53                     Log.i(TAG, "Nfc is disallowed by user for app: " + appName);
54                     finish();
55                 });
56     }
57 
58     @Override
onClick(View v)59     public void onClick(View v) {
60         NfcService sService = NfcService.getInstance();
61         sService.enableNfc();
62         finish();
63     }
64 }
65