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
17package com.android.tv.settings.system.development;
18
19import android.content.Context;
20import android.hardware.usb.IUsbManager;
21import android.os.Bundle;
22import android.os.IBinder;
23import android.os.RemoteException;
24import android.os.ServiceManager;
25import android.support.annotation.Keep;
26import android.support.annotation.NonNull;
27import android.support.v17.leanback.app.GuidedStepFragment;
28import android.support.v17.leanback.widget.GuidanceStylist;
29import android.support.v17.leanback.widget.GuidedAction;
30import android.util.Log;
31
32import com.android.tv.settings.R;
33
34import java.util.List;
35
36@Keep
37public class AdbKeysDialog extends GuidedStepFragment {
38    private static final String TAG = "AdbKeysDialog";
39
40    @NonNull
41    @Override
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
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
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