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

Commit d60a9d0e authored by fionaxu's avatar fionaxu
Browse files

app link handling under restricted mobile data

1. new actions to allow default carrier app dynamically enable/disable
app-link filtering
2. new intent to notify registered carrier apps of other default
networks
3. signal-to-actions config to sepcify carrier actions on default
network change
default network available -> disable intent filter for app-link
defaut network lost -> enable intent filter for app-link
4. new carrier actions to allow carrier apps to register/unregister
other network status dynmacially

Bug: 62487488
Test: Manual
Change-Id: Ie9fa9f3f4ca38f9f26a90a3dbf95f7f20a8ad773
parent 81977b89
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -28,4 +28,6 @@
    <backup-transport-whitelisted-service
        service="android/com.android.internal.backup.LocalTransportService" />

    <!-- Whitelist of bundled applications which all handle URLs to their websites by default -->
    <app-link package="com.android.carrierdefaultapp" />
</config>
+16 −1
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@
            <intent-filter>
                <action android:name="com.android.internal.telephony.CARRIER_SIGNAL_REDIRECTED" />
                <action android:name="com.android.internal.telephony.CARRIER_SIGNAL_RESET" />
                <action android:name="com.android.internal.telephony.CARRIER_SIGNAL_DEFAULT_NETWORK_AVAILABLE" />
                <action android:name="android.intent.action.LOCALE_CHANGED" />
            </intent-filter>
        </receiver>
@@ -48,5 +49,19 @@
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
        </activity>

        <activity-alias
            android:name="com.android.carrierdefaultapp.URLHandlerActivity"
            android:targetActivity="com.android.carrierdefaultapp.CaptivePortalLoginActivity"
            android:enabled="false" >
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="http" />
                <data android:scheme="https" />
                <data android:host="*" />
            </intent-filter>
        </activity-alias>
    </application>
</manifest>
+33 −5
Original line number Diff line number Diff line
@@ -20,6 +20,9 @@ import android.app.Activity;
import android.app.LoadedApk;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.net.ConnectivityManager;
import android.net.ConnectivityManager.NetworkCallback;
@@ -34,6 +37,7 @@ import android.os.Bundle;
import android.telephony.CarrierConfigManager;
import android.telephony.Rlog;
import android.telephony.SubscriptionManager;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.Log;
import android.util.TypedValue;
@@ -68,7 +72,7 @@ public class CaptivePortalLoginActivity extends Activity {
    private static final boolean DBG = true;

    private static final int SOCKET_TIMEOUT_MS = 10 * 1000;
    public static final int NETWORK_REQUEST_TIMEOUT_MS = 5 * 1000;
    private static final int NETWORK_REQUEST_TIMEOUT_MS = 5 * 1000;

    private URL mUrl;
    private Network mNetwork;
@@ -182,16 +186,19 @@ public class CaptivePortalLoginActivity extends Activity {
            CarrierActionUtils.applyCarrierAction(
                    CarrierActionUtils.CARRIER_ACTION_CANCEL_ALL_NOTIFICATIONS, getIntent(),
                    getApplicationContext());

            CarrierActionUtils.applyCarrierAction(
                    CarrierActionUtils.CARRIER_ACTION_DISABLE_DEFAULT_URL_HANDLER, getIntent(),
                    getApplicationContext());
            CarrierActionUtils.applyCarrierAction(
                    CarrierActionUtils.CARRIER_ACTION_DEREGISTER_DEFAULT_NETWORK_AVAIL, getIntent(),
                    getApplicationContext());
        }
        finishAndRemoveTask();
    }

    private URL getUrlForCaptivePortal() {
        String url = getIntent().getStringExtra(TelephonyIntents.EXTRA_REDIRECTION_URL_KEY);
        if (url.isEmpty()) {
            url = mCm.getCaptivePortalServerUrl();
        }
        if (TextUtils.isEmpty(url)) url = mCm.getCaptivePortalServerUrl();
        final CarrierConfigManager configManager = getApplicationContext()
                .getSystemService(CarrierConfigManager.class);
        final int subId = getIntent().getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
@@ -429,6 +436,27 @@ public class CaptivePortalLoginActivity extends Activity {
        }
    }

    /**
     * This alias presents the target activity, CaptivePortalLoginActivity, as a independent
     * entity with its own intent filter to handle URL links. This alias will be enabled/disabled
     * dynamically to handle url links based on the network conditions.
     */
    public static String getAlias(Context context) {
        try {
            PackageInfo p = context.getPackageManager().getPackageInfo(context.getPackageName(),
                    PackageManager.GET_ACTIVITIES | PackageManager.MATCH_DISABLED_COMPONENTS);
            for (ActivityInfo activityInfo : p.activities) {
                String targetActivity = activityInfo.targetActivity;
                if (CaptivePortalLoginActivity.class.getName().equals(targetActivity)) {
                    return activityInfo.name;
                }
            }
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }

    private static void logd(String s) {
        Rlog.d(TAG, s);
    }
+50 −0
Original line number Diff line number Diff line
@@ -19,8 +19,10 @@ import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.os.Bundle;
import android.telephony.SubscriptionManager;
@@ -49,6 +51,10 @@ public class CarrierActionUtils {
    public static final int CARRIER_ACTION_SHOW_PORTAL_NOTIFICATION          = 4;
    public static final int CARRIER_ACTION_SHOW_NO_DATA_SERVICE_NOTIFICATION = 5;
    public static final int CARRIER_ACTION_CANCEL_ALL_NOTIFICATIONS          = 6;
    public static final int CARRIER_ACTION_ENABLE_DEFAULT_URL_HANDLER        = 7;
    public static final int CARRIER_ACTION_DISABLE_DEFAULT_URL_HANDLER       = 8;
    public static final int CARRIER_ACTION_REGISTER_DEFAULT_NETWORK_AVAIL    = 9;
    public static final int CARRIER_ACTION_DEREGISTER_DEFAULT_NETWORK_AVAIL  = 10;

    public static void applyCarrierAction(int actionIdx, Intent intent, Context context) {
        switch (actionIdx) {
@@ -73,6 +79,18 @@ public class CarrierActionUtils {
            case CARRIER_ACTION_CANCEL_ALL_NOTIFICATIONS:
                onCancelAllNotifications(context);
                break;
            case CARRIER_ACTION_ENABLE_DEFAULT_URL_HANDLER:
                onEnableDefaultURLHandler(context);
                break;
            case CARRIER_ACTION_DISABLE_DEFAULT_URL_HANDLER:
                onDisableDefaultURLHandler(context);
                break;
            case CARRIER_ACTION_REGISTER_DEFAULT_NETWORK_AVAIL:
                onRegisterDefaultNetworkAvail(intent, context);
                break;
            case CARRIER_ACTION_DEREGISTER_DEFAULT_NETWORK_AVAIL:
                onDeregisterDefaultNetworkAvail(intent, context);
                break;
            default:
                loge("unsupported carrier action index: " + actionIdx);
        }
@@ -94,6 +112,38 @@ public class CarrierActionUtils {
        telephonyMgr.carrierActionSetMeteredApnsEnabled(subId, ENABLE);
    }

    private static void onEnableDefaultURLHandler(Context context) {
        logd("onEnableDefaultURLHandler");
        final PackageManager pm = context.getPackageManager();
        pm.setComponentEnabledSetting(
                new ComponentName(context, CaptivePortalLoginActivity.getAlias(context)),
                PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
    }

    private static void onDisableDefaultURLHandler(Context context) {
        logd("onDisableDefaultURLHandler");
        final PackageManager pm = context.getPackageManager();
        pm.setComponentEnabledSetting(
                new ComponentName(context, CaptivePortalLoginActivity.getAlias(context)),
                PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
    }

    private static void onRegisterDefaultNetworkAvail(Intent intent, Context context) {
        int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
                SubscriptionManager.getDefaultVoiceSubscriptionId());
        logd("onRegisterDefaultNetworkAvail subId: " + subId);
        final TelephonyManager telephonyMgr = context.getSystemService(TelephonyManager.class);
        telephonyMgr.carrierActionReportDefaultNetworkStatus(subId, true);
    }

    private static void onDeregisterDefaultNetworkAvail(Intent intent, Context context) {
        int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
                SubscriptionManager.getDefaultVoiceSubscriptionId());
        logd("onDeregisterDefaultNetworkAvail subId: " + subId);
        final TelephonyManager telephonyMgr = context.getSystemService(TelephonyManager.class);
        telephonyMgr.carrierActionReportDefaultNetworkStatus(subId, false);
    }

    private static void onDisableRadio(Intent intent, Context context) {
        int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
                SubscriptionManager.getDefaultVoiceSubscriptionId());
+6 −1
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import android.telephony.CarrierConfigManager;
import android.telephony.Rlog;
import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;

import com.android.internal.telephony.TelephonyIntents;
import com.android.internal.util.ArrayUtils;
@@ -95,6 +94,12 @@ public class CustomConfigLoader {
                    configs = b.getStringArray(CarrierConfigManager
                            .KEY_CARRIER_DEFAULT_ACTIONS_ON_RESET);
                    break;
                case TelephonyIntents.ACTION_CARRIER_SIGNAL_DEFAULT_NETWORK_AVAILABLE:
                    configs = b.getStringArray(CarrierConfigManager
                            .KEY_CARRIER_DEFAULT_ACTIONS_ON_DEFAULT_NETWORK_AVAILABLE);
                    arg1 = String.valueOf(intent.getBooleanExtra(TelephonyIntents
                            .EXTRA_DEFAULT_NETWORK_AVAILABLE_KEY, false));
                    break;
                default:
                    Rlog.e(TAG, "load carrier config failure with un-configured key: " +
                            intent.getAction());
Loading