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