[Satellite Settings] Show device's app info on Satellite settings page.

- Shows device apps' info up to 3 on Satellite settings' page.
 - Add a new page to show all device's app info with Satellite supported.

Flag: com.android.internal.telephony.flags.satellite_25q4_apis
Fix: b/395813844
Test: atest pass
Change-Id: Ibd5e1c74b636639082ec9477f2b6796bcbc8340d
This commit is contained in:
tom hsu
2025-02-12 03:29:45 +00:00
committed by Tom Hsu
parent 63242bc3ff
commit bb80fe2df1
8 changed files with 491 additions and 0 deletions

View File

@@ -0,0 +1,98 @@
/*
* Copyright (C) 2025 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.network.telephony;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
import com.android.internal.telephony.flags.Flags;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.network.SatelliteRepository;
import com.android.settingslib.Utils;
import java.util.List;
/** A controller to show some of apps info which supported on Satellite service. */
public class SatelliteAppListCategoryController extends BasePreferenceController {
private static final String TAG = "SatelliteAppListCategoryController";
@VisibleForTesting
static final int MAXIMUM_OF_PREFERENCE_AMOUNT = 3;
private List<String> mPackageNameList;
public SatelliteAppListCategoryController(
@NonNull Context context,
@NonNull String preferenceKey) {
super(context, preferenceKey);
}
/** Initialize the necessary applications' data*/
public void init() {
SatelliteRepository satelliteRepository = new SatelliteRepository(mContext);
init(satelliteRepository);
}
@VisibleForTesting
void init(@NonNull SatelliteRepository satelliteRepository) {
mPackageNameList = satelliteRepository.getSatelliteDataOptimizedApps();
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
PreferenceCategory preferenceCategory = screen.findPreference(getPreferenceKey());
for (int i = 0; i < mPackageNameList.size() && i < MAXIMUM_OF_PREFERENCE_AMOUNT; i++) {
String packageName = mPackageNameList.get(i);
ApplicationInfo appInfo = getApplicationInfo(mContext, packageName);
if (appInfo != null) {
Drawable icon = Utils.getBadgedIcon(mContext, appInfo);
CharSequence name = appInfo.loadLabel(mContext.getPackageManager());
Preference pref = new Preference(mContext);
pref.setIcon(icon);
pref.setTitle(name);
preferenceCategory.addPreference(pref);
}
}
}
@Override
public int getAvailabilityStatus() {
if (!Flags.satellite25q4Apis()) {
return CONDITIONALLY_UNAVAILABLE;
}
return mPackageNameList.isEmpty()
? CONDITIONALLY_UNAVAILABLE
: AVAILABLE;
}
static ApplicationInfo getApplicationInfo(Context context, String packageName) {
try {
PackageManager pm = context.getPackageManager();
return pm.getApplicationInfoAsUser(packageName, /* flags= */ 0, context.getUserId());
} catch (PackageManager.NameNotFoundException e) {
return null;
}
}
}

View File

@@ -0,0 +1,126 @@
/*
* Copyright (C) 2025 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.network.telephony;
import static com.android.settings.network.telephony.SatelliteAppListCategoryController.getApplicationInfo;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.graphics.drawable.Drawable;
import android.os.UserManager;
import android.util.Log;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.dashboard.RestrictedDashboardFragment;
import com.android.settings.network.SatelliteRepository;
import com.android.settingslib.Utils;
import com.android.settingslib.core.AbstractPreferenceController;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.List;
import java.util.stream.Collectors;
/** Shows all applications which support satellite service. */
public class SatelliteAppListFragment extends RestrictedDashboardFragment {
public SatelliteAppListFragment() {
super(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS);
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
use(SatelliteAppListPreferenceController.class).init();
}
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
SatelliteAppListPreferenceController satelliteAppListPreferenceController =
new SatelliteAppListPreferenceController(getContext());
return List.of(satelliteAppListPreferenceController);
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.satellite_settings_apps_list;
}
@Override
protected String getLogTag() {
return "SatelliteAppListFragment";
}
@Override
public int getMetricsCategory() {
return SettingsEnums.SATELLITE_APPS_LIST;
}
@VisibleForTesting
static class SatelliteAppListPreferenceController extends BasePreferenceController {
private static final String TAG = "SatelliteAppListPreferenceController";
private static final String KEY = "key_satellite_app_list";
private List<ApplicationInfo> mApplicationInfoList = List.of();
SatelliteAppListPreferenceController(@NonNull Context context) {
super(context, KEY);
}
public void init() {
SatelliteRepository satelliteRepository = new SatelliteRepository(mContext);
init(satelliteRepository);
}
void init(@NonNull SatelliteRepository satelliteRepository) {
mApplicationInfoList =
satelliteRepository.getSatelliteDataOptimizedApps()
.stream()
.map(name -> getApplicationInfo(mContext, name))
.collect(Collectors.toList());
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
if (mApplicationInfoList.isEmpty()) {
return;
}
mApplicationInfoList.forEach(appInfo -> {
if (appInfo != null) {
Log.i(TAG, "Add preference to UI : " + appInfo.packageName);
Drawable icon = Utils.getBadgedIcon(mContext, appInfo);
CharSequence name = appInfo.loadLabel(mContext.getPackageManager());
Preference pref = new Preference(mContext);
pref.setIcon(icon);
pref.setTitle(name);
screen.addPreference(pref);
}
});
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE;
}
}
}

View File

@@ -26,6 +26,7 @@ import static android.telephony.CarrierConfigManager.KEY_SATELLITE_INFORMATION_R
import android.app.Activity;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
@@ -92,6 +93,12 @@ public class SatelliteSetting extends RestrictedDashboardFragment {
return SettingsEnums.SATELLITE_SETTING;
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
use(SatelliteAppListCategoryController.class).init();
}
@Override
public void onCreate(@NonNull Bundle savedInstanceState) {
super.onCreate(savedInstanceState);