Home | History | Annotate | Download | only in usb
      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.systemui.usb;
     18 
     19 import android.app.Activity;
     20 import android.content.Intent;
     21 import android.hardware.usb.ParcelableUsbPort;
     22 import android.hardware.usb.UsbManager;
     23 import android.hardware.usb.UsbPort;
     24 import android.os.Bundle;
     25 import android.util.Log;
     26 import android.view.View;
     27 import android.view.Window;
     28 import android.view.WindowManager;
     29 import android.widget.TextView;
     30 import android.widget.Toast;
     31 
     32 import com.android.systemui.R;
     33 
     34 /**
     35  * Activity that alerts the user when contaminant is detected on USB port.
     36  */
     37 public class UsbContaminantActivity extends Activity implements View.OnClickListener {
     38     private static final String TAG = "UsbContaminantActivity";
     39 
     40     private UsbPort mUsbPort;
     41     private TextView mLearnMore;
     42     private TextView mGotIt;
     43     private TextView mEnableUsb;
     44     private TextView mTitle;
     45     private TextView mMessage;
     46 
     47     @Override
     48     public void onCreate(Bundle icicle) {
     49         Window window = getWindow();
     50         window.addSystemFlags(WindowManager.LayoutParams
     51                 .SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
     52         window.setType(WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG);
     53         requestWindowFeature(Window.FEATURE_NO_TITLE);
     54 
     55         super.onCreate(icicle);
     56         setContentView(R.layout.contaminant_dialog);
     57 
     58         Intent intent = getIntent();
     59         ParcelableUsbPort port = intent.getParcelableExtra(UsbManager.EXTRA_PORT);
     60         mUsbPort = port.getUsbPort(getSystemService(UsbManager.class));
     61 
     62         mLearnMore = findViewById(R.id.learnMore);
     63         mEnableUsb = findViewById(R.id.enableUsb);
     64         mGotIt = findViewById(R.id.gotIt);
     65         mTitle = findViewById(R.id.title);
     66         mMessage = findViewById(R.id.message);
     67 
     68         mTitle.setText(getString(R.string.usb_contaminant_title));
     69         mMessage.setText(getString(R.string.usb_contaminant_message));
     70         mEnableUsb.setText(getString(R.string.usb_disable_contaminant_detection));
     71         mGotIt.setText(getString(R.string.got_it));
     72         mLearnMore.setText(getString(R.string.learn_more));
     73 
     74         mEnableUsb.setOnClickListener(this);
     75         mGotIt.setOnClickListener(this);
     76         mLearnMore.setOnClickListener(this);
     77     }
     78 
     79     @Override
     80     public void onWindowAttributesChanged(WindowManager.LayoutParams params) {
     81         super.onWindowAttributesChanged(params);
     82     }
     83 
     84     @Override
     85     public void onClick(View v) {
     86         if (v == mEnableUsb) {
     87             try {
     88                 mUsbPort.enableContaminantDetection(false);
     89                 Toast.makeText(this, R.string.usb_port_enabled,
     90                     Toast.LENGTH_SHORT).show();
     91             } catch (Exception e) {
     92                 Log.e(TAG, "Unable to notify Usb service", e);
     93             }
     94         } else if (v == mLearnMore) {
     95             final Intent intent = new Intent();
     96             intent.setClassName("com.android.settings",
     97                     "com.android.settings.HelpTrampoline");
     98             intent.putExtra(Intent.EXTRA_TEXT,
     99                     "help_url_usb_contaminant_detected");
    100             startActivity(intent);
    101         }
    102         finish();
    103     }
    104 }
    105