Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 28f5fbb5 authored by Tom Hsu's avatar Tom Hsu Committed by Android (Google) Code Review
Browse files

Merge "[Satellite Settings] Show device's app info on Satellite settings page." into main

parents ce85d2ea bb80fe2d
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -12607,6 +12607,12 @@
    <string name="description_satellite_setting_messaging">satellite messaging</string>
    <!-- Title for notifying user's account be able to use data transmission of Satellite" [CHAR_LIMIT=NONE] -->
    <string name="title_have_satellite_data_plan">Use of data is included with your account</string>
    <!-- Category title for Satellite supported apps info  [CHAR LIMIT=60] -->
    <string name="category_title_satellite_supported_apps">Supported apps on your phone</string>
    <!-- Title for a entry to start apps list page with Satellite service supported.  [CHAR LIMIT=60] -->
    <string name="title_satellite_supported_app_list_entry">see all apps</string>
    <!-- Title for a page of apps list page with Satellite service supported.  [CHAR LIMIT=60] -->
    <string name="title_satellite_supported_app_list_page">Supported apps on your phone</string>
    <!-- Title for Apn settings in mobile network settings [CHAR LIMIT=60] -->
    <string name="mobile_network_apn_title">Access Point Names</string>
+17 −0
Original line number Diff line number Diff line
@@ -62,6 +62,23 @@
            android:icon="@drawable/ic_android_satellite_24px"/>
    </PreferenceCategory>

    <PreferenceCategory
        android:key="key_category_satellite_apps"
        android:title="@string/category_title_satellite_supported_apps"
        settings:isPreferenceVisible="false"
        settings:controller="com.android.settings.network.telephony.SatelliteAppListCategoryController"
        settings:searchable="false">

        <!-- See all satellite apps -->
        <Preference
            android:key="key_see_all_satellite_apps"
            android:title="@string/title_satellite_supported_app_list_entry"
            android:icon="@drawable/ic_chevron_right_24dp"
            android:fragment="com.android.settings.network.telephony.SatelliteAppListFragment"
            android:order="5"
            settings:searchable="false"/>
    </PreferenceCategory>

    <com.android.settingslib.widget.FooterPreference
        android:key="satellite_setting_extra_info_footer_pref"
        android:layout="@layout/satellite_setting_more_information_layout"
+21 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?><!--
  ~ 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.
  -->

<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:settings="http://schemas.android.com/tools"
    android:key="key_satellite_app_list"
    android:title="@string/title_satellite_supported_app_list_page">
</androidx.preference.PreferenceScreen>
 No newline at end of file
+98 −0
Original line number Diff line number Diff line
/*
 * 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;
        }
    }
}
+126 −0
Original line number Diff line number Diff line
/*
 * 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;
        }
    }
}
Loading