Align with the visibility logic from Dialer
Copy most visiblity logic from the Dialer app We should check whether RTT is supported or not by querying Telecom. Also, the rtt configuration won't be initialized properly before user goes into the RTT page. Prior to this cl, we set a wrong default value when we're showing the subtext of RTT, this is not correct. Currently, we simple show nothing in subtext if RTT haven't initilized properly. Test: Work with testing team to verify the behavior. Fix: 188110773 Change-Id: I47c1983d15e22ef5a1fb3027334117a38a479558
This commit is contained in:
81
src/com/android/settings/accessibility/rtt/TelecomUtil.java
Normal file
81
src/com/android/settings/accessibility/rtt/TelecomUtil.java
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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.accessibility.rtt;
|
||||
|
||||
import android.content.Context;
|
||||
import android.telecom.PhoneAccountHandle;
|
||||
import android.telecom.TelecomManager;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* A util class checks some SIM card information and permissions.
|
||||
*/
|
||||
public abstract class TelecomUtil {
|
||||
|
||||
private static final String TAG = "TelecomUtil";
|
||||
|
||||
/** Get a list of phone accounts which are call capable. */
|
||||
public static List<PhoneAccountHandle> getCallCapablePhoneAccounts(Context context) {
|
||||
return Optional.ofNullable(getTelecomManager(context).getCallCapablePhoneAccounts())
|
||||
.orElse(new ArrayList<>());
|
||||
}
|
||||
|
||||
/** Returns a {@link TelecomManager} instance. */
|
||||
public static TelecomManager getTelecomManager(Context context) {
|
||||
return context.getApplicationContext().getSystemService(TelecomManager.class);
|
||||
}
|
||||
|
||||
/** Returns a subscription id of the SIM. */
|
||||
public static int getSubIdForPhoneAccountHandle(
|
||||
Context context, PhoneAccountHandle phoneAccountHandle) {
|
||||
Optional<SubscriptionInfo> info = getSubscriptionInfo(context, phoneAccountHandle);
|
||||
return info.map(SubscriptionInfo::getSubscriptionId)
|
||||
.orElse(SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the {@link SubscriptionInfo} of the SIM if {@code phoneAccountHandle} corresponds
|
||||
* to a valid SIM. Absent otherwise.
|
||||
*/
|
||||
private static Optional<SubscriptionInfo> getSubscriptionInfo(
|
||||
Context context, PhoneAccountHandle phoneAccountHandle) {
|
||||
if (TextUtils.isEmpty(phoneAccountHandle.getId())) {
|
||||
return Optional.empty();
|
||||
}
|
||||
SubscriptionManager subscriptionManager = context.getSystemService(
|
||||
SubscriptionManager.class);
|
||||
List<SubscriptionInfo> subscriptionInfos =
|
||||
subscriptionManager.getActiveSubscriptionInfoList();
|
||||
if (subscriptionInfos == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
for (SubscriptionInfo info : subscriptionInfos) {
|
||||
if (phoneAccountHandle.getId().startsWith(info.getIccId())) {
|
||||
return Optional.of(info);
|
||||
}
|
||||
}
|
||||
Log.d(TAG, "Failed to find SubscriptionInfo for phoneAccountHandle");
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user