diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 426aebff81a..2b4bcaed88e 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -2196,6 +2196,8 @@ + + diff --git a/res/layout-land/adb_qrcode_scanner_fragment.xml b/res/layout-land/adb_qrcode_scanner_fragment.xml new file mode 100644 index 00000000000..64515510c44 --- /dev/null +++ b/res/layout-land/adb_qrcode_scanner_fragment.xml @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/layout/adb_qrcode_scanner_fragment.xml b/res/layout/adb_qrcode_scanner_fragment.xml index 5b83cb2f33a..78231554319 100644 --- a/res/layout/adb_qrcode_scanner_fragment.xml +++ b/res/layout/adb_qrcode_scanner_fragment.xml @@ -17,10 +17,11 @@ + android:icon="@drawable/ic_scan_32dp" + app:sudDescriptionText="@string/adb_wireless_qrcode_pairing_description"> - + + + + + - - - - - - - - - - - + android:visibility="invisible"/> @@ -109,4 +92,5 @@ + diff --git a/src/com/android/settings/development/AdbQrCodeActivity.java b/src/com/android/settings/development/AdbQrCodeActivity.java new file mode 100644 index 00000000000..bab20f9754a --- /dev/null +++ b/src/com/android/settings/development/AdbQrCodeActivity.java @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.development; + +import android.app.settings.SettingsEnums; +import android.content.Intent; +import android.os.Bundle; + +import androidx.fragment.app.FragmentTransaction; + +import com.android.settings.R; +import com.android.settings.wifi.dpp.WifiDppBaseActivity; + +/** + * To scan an ADB QR code to pair a device. + * + * To use intent action {@code ACTION_ADB_QR_CODE_SCANNER}. + */ +public class AdbQrCodeActivity extends WifiDppBaseActivity { + private static final String TAG = "AdbQrCodeActivity"; + + static final String TAG_FRAGMENT_ADB_QR_CODE_SCANNER = "adb_qr_code_scanner_fragment"; + + public static final String ACTION_ADB_QR_CODE_SCANNER = + "android.settings.ADB_QR_CODE_SCANNER"; + + @Override + public int getMetricsCategory() { + return SettingsEnums.SETTINGS_ADB_WIRELESS; + } + + @Override + protected void onCreate(Bundle icicle) { + super.onCreate(icicle); + AdbQrcodeScannerFragment fragment = + (AdbQrcodeScannerFragment) mFragmentManager.findFragmentByTag( + TAG_FRAGMENT_ADB_QR_CODE_SCANNER); + + if (fragment == null) { + fragment = new AdbQrcodeScannerFragment(); + } else { + if (fragment.isVisible()) { + return; + } + + // When the fragment in back stack but not on top of the stack, we can simply pop + // stack because current fragment transactions are arranged in an order + mFragmentManager.popBackStackImmediate(); + return; + } + final FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction(); + + fragmentTransaction.replace(R.id.fragment_container, fragment, + TAG_FRAGMENT_ADB_QR_CODE_SCANNER); + fragmentTransaction.commit(); + } + + @Override + protected void handleIntent(Intent intent) { + } +} diff --git a/src/com/android/settings/development/AdbQrCodePreferenceController.java b/src/com/android/settings/development/AdbQrCodePreferenceController.java index 7c1ae12538d..9085d1ba848 100644 --- a/src/com/android/settings/development/AdbQrCodePreferenceController.java +++ b/src/com/android/settings/development/AdbQrCodePreferenceController.java @@ -16,8 +16,8 @@ package com.android.settings.development; -import android.app.settings.SettingsEnums; import android.content.Context; +import android.content.Intent; import android.debug.IAdbManager; import android.os.RemoteException; import android.os.ServiceManager; @@ -28,7 +28,6 @@ import androidx.fragment.app.Fragment; import androidx.preference.Preference; import com.android.settings.core.BasePreferenceController; -import com.android.settings.core.SubSettingLauncher; /** * Controller for the "Pair device with QR code" preference in the Wireless debugging @@ -68,12 +67,9 @@ public class AdbQrCodePreferenceController extends BasePreferenceController { return false; } - new SubSettingLauncher(preference.getContext()) - .setDestination(AdbQrcodeScannerFragment.class.getName()) - .setSourceMetricsCategory(SettingsEnums.SETTINGS_ADB_WIRELESS) - .setResultListener(mParentFragment, - WirelessDebuggingFragment.PAIRING_DEVICE_REQUEST) - .launch(); + final Intent intent = new Intent(mContext, AdbQrCodeActivity.class); + mParentFragment.startActivityForResult(intent, + WirelessDebuggingFragment.PAIRING_DEVICE_REQUEST); return true; } } diff --git a/src/com/android/settings/development/AdbQrcodeScannerFragment.java b/src/com/android/settings/development/AdbQrcodeScannerFragment.java index 7a30443bca4..1035fbeab33 100644 --- a/src/com/android/settings/development/AdbQrcodeScannerFragment.java +++ b/src/com/android/settings/development/AdbQrcodeScannerFragment.java @@ -44,12 +44,15 @@ import android.widget.TextView; import androidx.annotation.StringRes; import com.android.settings.R; +import com.android.settings.SetupWizardUtils; import com.android.settings.wifi.dpp.AdbQrCode; import com.android.settings.wifi.dpp.WifiDppQrCodeBaseFragment; import com.android.settings.wifi.dpp.WifiNetworkConfig; import com.android.settings.wifi.qrcode.QrCamera; import com.android.settings.wifi.qrcode.QrDecorateView; +import com.google.android.setupdesign.util.ThemeHelper; + /** * Fragment shown when clicking on the "Pair by QR code" preference in * the Wireless Debugging fragment. @@ -144,6 +147,9 @@ public class AdbQrcodeScannerFragment extends WifiDppQrCodeBaseFragment implemen @Override public void onCreate(Bundle savedInstanceState) { + Context context = getContext(); + context.setTheme(SetupWizardUtils.getTheme(context, getActivity().getIntent())); + ThemeHelper.trySetDynamicColor(getContext()); super.onCreate(savedInstanceState); mIntentFilter = new IntentFilter(AdbManager.WIRELESS_DEBUG_PAIRING_RESULT_ACTION); @@ -158,6 +164,7 @@ public class AdbQrcodeScannerFragment extends WifiDppQrCodeBaseFragment implemen @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); + mSummary = view.findViewById(R.id.sud_layout_subtitle); mTextureView = (TextureView) view.findViewById(R.id.preview_view); mTextureView.setSurfaceTextureListener(this); @@ -165,8 +172,6 @@ public class AdbQrcodeScannerFragment extends WifiDppQrCodeBaseFragment implemen mDecorateView = view.findViewById(R.id.decorate_view); setProgressBarShown(false); - setHeaderIconImageResource(R.drawable.ic_scan_24dp); - mQrCameraView = view.findViewById(R.id.camera_layout); mVerifyingView = view.findViewById(R.id.verifying_layout); mVerifyingTextView = view.findViewById(R.id.verifying_textview); @@ -181,12 +186,18 @@ public class AdbQrcodeScannerFragment extends WifiDppQrCodeBaseFragment implemen public void onResume() { super.onResume(); + restartCamera(); + mAdbManager = IAdbManager.Stub.asInterface(ServiceManager.getService(Context.ADB_SERVICE)); getActivity().registerReceiver(mReceiver, mIntentFilter); } @Override public void onPause() { + if (mCamera != null) { + mCamera.stop(); + } + super.onPause(); getActivity().unregisterReceiver(mReceiver); @@ -195,8 +206,6 @@ public class AdbQrcodeScannerFragment extends WifiDppQrCodeBaseFragment implemen } catch (RemoteException e) { Log.e(TAG, "Unable to cancel pairing"); } - getActivity().setResult(Activity.RESULT_CANCELED); - getActivity().finish(); } @Override @@ -213,7 +222,6 @@ public class AdbQrcodeScannerFragment extends WifiDppQrCodeBaseFragment implemen public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - getActivity().getActionBar().hide(); // setTitle for TalkBack getActivity().setTitle(R.string.wifi_dpp_scan_qr_code); } diff --git a/src/com/android/settings/wifi/dpp/WifiDppBaseActivity.java b/src/com/android/settings/wifi/dpp/WifiDppBaseActivity.java index 499f66cb3c8..f55960be5e0 100644 --- a/src/com/android/settings/wifi/dpp/WifiDppBaseActivity.java +++ b/src/com/android/settings/wifi/dpp/WifiDppBaseActivity.java @@ -26,7 +26,7 @@ import com.android.settings.R; import com.android.settings.SetupWizardUtils; import com.android.settings.core.InstrumentedActivity; -abstract class WifiDppBaseActivity extends InstrumentedActivity { +public abstract class WifiDppBaseActivity extends InstrumentedActivity { protected FragmentManager mFragmentManager; protected abstract void handleIntent(Intent intent);