1. Check open from a notification 2. Check open from Bluetooth entry 3. If the inputDeviceIdentifier is not null, open the next page directly. 4. Add extra to record the class of sender for the future metrics. Demo: http://screencast/cast/NDU4MTYxOTIzMTg4MzI2NHxiYTQ0ODE5Ny02YQ Bug: 269212353 Test: manual, atest [Pass] atest KeyboardSettingsPreferenceControllerTest [Pass] atest PhysicalKeyboardPreferenceControllerTest Change-Id: Ie874003260896bbb949806623913e70486e4731d
90 lines
3.4 KiB
Java
90 lines
3.4 KiB
Java
/*
|
|
* Copyright (C) 2022 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.inputmethod;
|
|
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.provider.Settings;
|
|
import android.util.FeatureFlagUtils;
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.VisibleForTesting;
|
|
import androidx.preference.Preference;
|
|
|
|
import com.android.settings.core.BasePreferenceController;
|
|
import com.android.settings.inputmethod.PhysicalKeyboardFragment.HardKeyboardDeviceInfo;
|
|
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
|
|
|
import java.util.List;
|
|
|
|
public class KeyboardSettingsPreferenceController extends BasePreferenceController {
|
|
|
|
private CachedBluetoothDevice mCachedDevice;
|
|
|
|
public KeyboardSettingsPreferenceController(Context context, String key) {
|
|
super(context, key);
|
|
}
|
|
|
|
public void init(@NonNull CachedBluetoothDevice cachedDevice) {
|
|
mCachedDevice = cachedDevice;
|
|
}
|
|
|
|
@Override
|
|
public boolean handlePreferenceTreeClick(Preference preference) {
|
|
if (!getPreferenceKey().equals(preference.getKey())) {
|
|
return false;
|
|
}
|
|
List<HardKeyboardDeviceInfo> newHardKeyboards = getHardKeyboardList();
|
|
for (HardKeyboardDeviceInfo hardKeyboardDeviceInfo : newHardKeyboards) {
|
|
if (mCachedDevice.getAddress().equals(hardKeyboardDeviceInfo.mBluetoothAddress)) {
|
|
Intent intent = new Intent(Settings.ACTION_HARD_KEYBOARD_SETTINGS);
|
|
intent.putExtra(
|
|
NewKeyboardSettingsUtils.EXTRA_INTENT_FROM,
|
|
"com.android.settings.inputmethod.KeyboardSettingsPreferenceController");
|
|
intent.putExtra(
|
|
Settings.EXTRA_INPUT_DEVICE_IDENTIFIER,
|
|
hardKeyboardDeviceInfo.mDeviceIdentifier);
|
|
mContext.startActivity(intent);
|
|
break;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public int getAvailabilityStatus() {
|
|
List<HardKeyboardDeviceInfo> newHardKeyboards = getHardKeyboardList();
|
|
if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SETTINGS_NEW_KEYBOARD_UI)
|
|
&& !newHardKeyboards.isEmpty()) {
|
|
for (HardKeyboardDeviceInfo hardKeyboardDeviceInfo : newHardKeyboards) {
|
|
if (mCachedDevice.getAddress() != null
|
|
&& hardKeyboardDeviceInfo.mBluetoothAddress != null
|
|
&& mCachedDevice.getAddress().equals(
|
|
hardKeyboardDeviceInfo.mBluetoothAddress)) {
|
|
return AVAILABLE;
|
|
}
|
|
}
|
|
}
|
|
return CONDITIONALLY_UNAVAILABLE;
|
|
}
|
|
|
|
@VisibleForTesting
|
|
List<HardKeyboardDeviceInfo> getHardKeyboardList() {
|
|
return PhysicalKeyboardFragment.getHardKeyboards(mContext);
|
|
}
|
|
}
|