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

Commit 0ce7202d authored by Charlotte Lu's avatar Charlotte Lu
Browse files

Use flag to switch to the new UI.

Bug: 194175217
Test: Munual
Change-Id: Ie3047cebd4a79dea07614b48ad33ba759802cbe8
parent 089318d9
Loading
Loading
Loading
Loading
+75 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.apn

import android.content.Context
import android.net.Uri
import android.os.Bundle
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.navigation.NavType
import androidx.navigation.navArgument
import com.android.settings.R
import com.android.settingslib.spa.framework.common.SettingsPageProvider
import com.android.settingslib.spa.widget.scaffold.RegularScaffold
import java.util.Base64

const val URI_TYPE = "uriType"
const val URI = "uri"
const val SUB_ID = "subId"
const val MVNO_TYPE = "mvnoType"
const val MVNO_MATCH_DATA = "mvnoMatchData"
const val EDIT_URL = "editUrl"

object ApnEditPageProvider : SettingsPageProvider {

    override val name = "Apn"
    const val TAG = "ApnPageProvider"

    override val parameter = listOf(
        navArgument(URI_TYPE) { type = NavType.StringType },
        navArgument(URI) { type = NavType.StringType },
        navArgument(SUB_ID) { type = NavType.IntType },
        navArgument(MVNO_TYPE) { type = NavType.StringType },
        navArgument(MVNO_MATCH_DATA) { type = NavType.StringType },
    )

    @Composable
    override fun Page(arguments: Bundle?) {
        val context = LocalContext.current
        ApnPage(context)
    }

    fun getRoute(
        uriType: String,
        uri: Uri,
        subId: Int,
        mMvnoType: String,
        mMvnoMatchData: String
    ): String = "${name}/$uriType/${
        Base64.getUrlEncoder().encodeToString(uri.toString().toByteArray())
    }/$subId/$mMvnoType/$mMvnoMatchData"
}

@Composable
fun ApnPage(context: Context) {
    RegularScaffold(
        title = stringResource(id = R.string.apn_edit),
    ) {
    }
}
 No newline at end of file
+28 −19
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.settings.network.apn;

import static com.android.settings.network.apn.ApnEditPageProviderKt.EDIT_URL;

import android.content.ContentUris;
import android.content.Context;
import android.content.Intent;
@@ -34,15 +36,21 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;

import com.android.settings.R;
import com.android.settings.flags.Flags;
import com.android.settings.spa.SpaActivity;

/**
 * Preference of APN UI entry
 */
public class ApnPreference extends Preference implements CompoundButton.OnCheckedChangeListener,
        View.OnClickListener {
public class ApnPreference extends Preference
        implements CompoundButton.OnCheckedChangeListener, View.OnClickListener {
    private static final String TAG = "ApnPreference";

    private static String sSelectedKey = null;
    private static CompoundButton sCurrentChecked = null;
    private int mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
    private boolean mProtectFromCheckedChange = false;
    private boolean mSelectable = true;
    private boolean mHideDetails = false;

    /**
     * Constructor of Preference
@@ -65,12 +73,6 @@ public class ApnPreference extends Preference implements CompoundButton.OnChecke
        this(context, null);
    }

    private static String sSelectedKey = null;
    private static CompoundButton sCurrentChecked = null;
    private boolean mProtectFromCheckedChange = false;
    private boolean mSelectable = true;
    private boolean mHideDetails = false;

    @Override
    public void onBindViewHolder(PreferenceViewHolder view) {
        super.onBindViewHolder(view);
@@ -147,25 +149,32 @@ public class ApnPreference extends Preference implements CompoundButton.OnChecke
        }

        if (mHideDetails) {
            Toast.makeText(context, context.getString(
                    R.string.cannot_change_apn_toast), Toast.LENGTH_LONG).show();
            Toast.makeText(context, context.getString(R.string.cannot_change_apn_toast),
                    Toast.LENGTH_LONG).show();
            return;
        }

        final Uri url = ContentUris.withAppendedId(Telephony.Carriers.CONTENT_URI, pos);

        if (Flags.newApnPageEnabled()) {
            String route = ApnEditPageProvider.INSTANCE.getRoute(EDIT_URL, url, mSubId, "_", "_");
            SpaActivity.startSpaActivity(context, route);
        } else {
            final Intent editIntent = new Intent(Intent.ACTION_EDIT, url);
            editIntent.putExtra(ApnSettings.SUB_ID, mSubId);
            editIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            context.startActivity(editIntent);
        }

    public void setSelectable(boolean selectable) {
        mSelectable = selectable;
    }

    public boolean getSelectable() {
        return mSelectable;
    }

    public void setSelectable(boolean selectable) {
        mSelectable = selectable;
    }

    public void setSubId(int subId) {
        mSubId = subId;
    }
+3 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.settings.spa

import android.content.Context
import android.util.FeatureFlagUtils
import com.android.settings.network.apn.ApnEditPageProvider
import com.android.settings.spa.about.AboutPhonePageProvider
import com.android.settings.spa.app.AllAppListPageProvider
import com.android.settings.spa.app.AppsMainPageProvider
@@ -34,8 +35,8 @@ import com.android.settings.spa.app.specialaccess.ModifySystemSettingsAppListPro
import com.android.settings.spa.app.specialaccess.NfcTagAppsSettingsProvider
import com.android.settings.spa.app.specialaccess.PictureInPictureListProvider
import com.android.settings.spa.app.specialaccess.SpecialAppAccessPageProvider
import com.android.settings.spa.app.specialaccess.WifiControlAppListProvider
import com.android.settings.spa.app.specialaccess.UseFullScreenIntentAppListProvider
import com.android.settings.spa.app.specialaccess.WifiControlAppListProvider
import com.android.settings.spa.app.storage.StorageAppListPageProvider
import com.android.settings.spa.core.instrumentation.SpaLogProvider
import com.android.settings.spa.development.UsageStatsPageProvider
@@ -95,6 +96,7 @@ open class SettingsSpaEnvironment(context: Context) : SpaEnvironment(context) {
                AboutPhonePageProvider,
                StorageAppListPageProvider.Apps,
                StorageAppListPageProvider.Games,
                ApnEditPageProvider,
                ) + togglePermissionAppListTemplate.createPageProviders(),
            rootPages = listOf(
                HomePageProvider.createSettingsPage()