• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.tv.settings.system.development;
18 
19 import android.content.Context;
20 import android.hardware.usb.IUsbManager;
21 import android.os.Bundle;
22 import android.os.IBinder;
23 import android.os.RemoteException;
24 import android.os.ServiceManager;
25 import android.support.annotation.Keep;
26 import android.support.annotation.NonNull;
27 import android.support.v17.leanback.app.GuidedStepFragment;
28 import android.support.v17.leanback.widget.GuidanceStylist;
29 import android.support.v17.leanback.widget.GuidedAction;
30 import android.util.Log;
31 
32 import com.android.tv.settings.R;
33 
34 import java.util.List;
35 
36 @Keep
37 public class AdbKeysDialog extends GuidedStepFragment {
38     private static final String TAG = "AdbKeysDialog";
39 
40     @NonNull
41     @Override
onCreateGuidance(Bundle savedInstanceState)42     public GuidanceStylist.Guidance onCreateGuidance(Bundle savedInstanceState) {
43         return new GuidanceStylist.Guidance(
44                 getString(R.string.clear_adb_keys),
45                 getString(R.string.adb_keys_warning_message),
46                 null,
47                 null);
48     }
49 
50     @Override
onCreateActions(@onNull List<GuidedAction> actions, Bundle savedInstanceState)51     public void onCreateActions(@NonNull List<GuidedAction> actions, Bundle savedInstanceState) {
52         final Context context = getContext();
53         actions.add(new GuidedAction.Builder(context)
54                 .clickAction(GuidedAction.ACTION_ID_OK).build());
55         actions.add(new GuidedAction.Builder(context)
56                 .clickAction(GuidedAction.ACTION_ID_CANCEL).build());
57     }
58 
59     @Override
onGuidedActionClicked(GuidedAction action)60     public void onGuidedActionClicked(GuidedAction action) {
61         if (action.getId() == GuidedAction.ACTION_ID_OK) {
62             try {
63                 IBinder b = ServiceManager.getService(Context.USB_SERVICE);
64                 IUsbManager service = IUsbManager.Stub.asInterface(b);
65                 service.clearUsbDebuggingKeys();
66             } catch (RemoteException e) {
67                 Log.e(TAG, "Unable to clear adb keys", e);
68             }
69             getFragmentManager().popBackStack();
70         } else {
71             getFragmentManager().popBackStack();
72         }
73     }
74 }
75