When launch setting page for specific keyboard, it will route to PK setting first, add flag NO_HISTORY to make PK setting not been added in stack. So that when user navigate back, it will not back to PK setting, which will be more consistent. Update navigation path from: Device Detail -> Physical Keyboard Setting -> Keyboard Detail Setting to Device Detail -> Keyboard Detail Setting Bug: 330130137 Flag: N/A Test: verify on device Change-Id: I8d6d6a8a534dec5cd7330c4d47b38a46be76fc4d
90 lines
3.3 KiB
Java
90 lines
3.3 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.app.settings.SettingsEnums;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.provider.Settings;
|
|
|
|
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.setPackage(mContext.getPackageName());
|
|
intent.putExtra(
|
|
Settings.EXTRA_ENTRYPOINT, SettingsEnums.CONNECTED_DEVICES_SETTINGS);
|
|
intent.putExtra(
|
|
Settings.EXTRA_INPUT_DEVICE_IDENTIFIER,
|
|
hardKeyboardDeviceInfo.mDeviceIdentifier);
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
|
|
mContext.startActivity(intent);
|
|
break;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public int getAvailabilityStatus() {
|
|
List<HardKeyboardDeviceInfo> newHardKeyboards = getHardKeyboardList();
|
|
if (!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);
|
|
}
|
|
}
|