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

Commit 9f671d8e authored by Makoto Onuki's avatar Makoto Onuki Committed by Automerger Merge Worker
Browse files

Merge "Disable component alias" into udc-dev am: 6b539038

parents 26c8c46d 6b539038
Loading
Loading
Loading
Loading
+5 −31
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import android.content.pm.PackageManagerInternal;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.os.Binder;
import android.os.Build;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.text.TextUtils;
@@ -43,7 +42,6 @@ import com.android.internal.content.PackageMonitor;
import com.android.internal.os.BackgroundThread;
import com.android.server.FgThread;
import com.android.server.LocalServices;
import com.android.server.compat.CompatChange;
import com.android.server.compat.PlatformCompat;

import java.io.PrintWriter;
@@ -52,26 +50,11 @@ import java.util.Objects;
import java.util.function.Supplier;

/**
 * Manages and handles component aliases, which is an experimental feature.
 * @deprecated This feature is no longer used. Delete this class.
 *
 * NOTE: THIS CLASS IS PURELY EXPERIMENTAL AND WILL BE REMOVED IN FUTURE ANDROID VERSIONS.
 * DO NOT USE IT.
 *
 * "Component alias" allows an android manifest component (for now only broadcasts and services)
 * to be defined in one android package while having the implementation in a different package.
 *
 * When/if this becomes a real feature, it will be most likely implemented very differently,
 * which is why this shouldn't be used.
 *
 * For now, because this is an experimental feature to evaluate feasibility, the implementation is
 * "quick & dirty". For example, to define aliases, we use a regular intent filter and meta-data
 * in the manifest, instead of adding proper tags/attributes to AndroidManifest.xml.
 *
 * This feature is disabled by default.
 *
 * Also, for now, aliases can be defined across packages with different certificates, but
 * in a final version this will most likely be tightened.
 * Also delete Intnt.(set|get)OriginalIntent.
 */
@Deprecated
public class ComponentAliasResolver {
    private static final String TAG = "ComponentAliasResolver";
    private static final boolean DEBUG = true;
@@ -149,11 +132,6 @@ public class ComponentAliasResolver {
        }
    };

    private final CompatChange.ChangeListener mCompatChangeListener = (packageName) -> {
        if (DEBUG) Slog.d(TAG, "USE_EXPERIMENTAL_COMPONENT_ALIAS changed.");
        BackgroundThread.getHandler().post(this::refresh);
    };

    /**
     * Call this on systemRead().
     */
@@ -161,8 +139,6 @@ public class ComponentAliasResolver {
        synchronized (mLock) {
            mPlatformCompat = (PlatformCompat) ServiceManager.getService(
                    Context.PLATFORM_COMPAT_SERVICE);
            mPlatformCompat.registerListener(USE_EXPERIMENTAL_COMPONENT_ALIAS,
                    mCompatChangeListener);
        }
        if (DEBUG) Slog.d(TAG, "Compat listener set.");
        update(enabledByDeviceConfig, overrides);
@@ -176,10 +152,8 @@ public class ComponentAliasResolver {
            if (mPlatformCompat == null) {
                return; // System not ready.
            }
            final boolean enabled = Build.isDebuggable()
                    && (enabledByDeviceConfig
                        || mPlatformCompat.isChangeEnabledByPackageName(
                        USE_EXPERIMENTAL_COMPONENT_ALIAS, "android", UserHandle.USER_SYSTEM));
            // Never enable it.
            final boolean enabled = false;
            if (enabled != mEnabled) {
                Slog.i(TAG, (enabled ? "Enabling" : "Disabling") + " component aliases...");
                FgThread.getHandler().post(() -> {
+3 −51
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@ package {
    default_applicable_licenses: ["Android-Apache-2.0"],
}

// TODO: Delete this file. It's no longer needed, but removing it on udc-dev will cause
// a conflict on master.

java_defaults {
    name: "ComponentAliasTests_defaults",
    static_libs: [
@@ -34,54 +37,3 @@ java_defaults {
    ],
    platform_apis: true, // We use hidden APIs in the test.
}

// We build three APKs from the exact same source files, so these APKs contain the exact same tests.
// And we run the tests on each APK, so that we can test various situations:
// - When the alias is in the same package, target in the same package.
// - When the alias is in the same package, target in another package.
// - When the alias is in another package, which also contains the target.
// - When the alias is in another package, and the target is in yet another package.
// etc etc...

android_test {
    name: "ComponentAliasTests",
    defaults: [
        "ComponentAliasTests_defaults",
    ],
    package_name: "android.content.componentalias.tests",
    manifest: "AndroidManifest.xml",
    additional_manifests: [
        "AndroidManifest_main.xml",
        "AndroidManifest_service_aliases.xml",
        "AndroidManifest_service_targets.xml",
    ],
    test_config_template: "AndroidTest-template.xml",
}

android_test {
    name: "ComponentAliasTests1",
    defaults: [
        "ComponentAliasTests_defaults",
    ],
    package_name: "android.content.componentalias.tests.sub1",
    manifest: "AndroidManifest.xml",
    additional_manifests: [
        "AndroidManifest_sub1.xml",
        "AndroidManifest_service_targets.xml",
    ],
    test_config_template: "AndroidTest-template.xml",
}

android_test {
    name: "ComponentAliasTests2",
    defaults: [
        "ComponentAliasTests_defaults",
    ],
    package_name: "android.content.componentalias.tests.sub2",
    manifest: "AndroidManifest.xml",
    additional_manifests: [
        "AndroidManifest_sub2.xml",
        "AndroidManifest_service_targets.xml",
    ],
    test_config_template: "AndroidTest-template.xml",
}
+0 −25
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
 * 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.
 -->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="android.content.componentalias.tests" >

    <application>
        <uses-library android:name="android.test.runner" />
        <property android:name="com.android.EXPERIMENTAL_COMPONENT_ALIAS_OPT_IN" android:value="true" />
    </application>
</manifest>
+0 −28
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
 * 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.
 -->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="android.content.componentalias.tests" >

    <application>
    </application>

    <instrumentation
        android:name="androidx.test.runner.AndroidJUnitRunner"
        android:targetPackage="android.content.componentalias.tests" >
    </instrumentation>
</manifest>
+0 −81
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
 * 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.
 -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="android.content.componentalias.tests" >
    <application>
        <!--
            Note the alias components are essentially just placeholders, so the APKs don't have to
            have the implementation classes.
        -->
        <service android:name=".s.Alias00" android:exported="true" android:enabled="true" >
            <meta-data android:name="alias_target" android:value="android.content.componentalias.tests/android.content.componentalias.tests.s.Target00" />
            <intent-filter><action android:name="com.android.intent.action.EXPERIMENTAL_IS_ALIAS" /></intent-filter>
            <intent-filter><action android:name="android.content.componentalias.tests.IS_ALIAS_00" /></intent-filter>
        </service>
        <service android:name=".s.Alias01" android:exported="true" android:enabled="true" >
            <meta-data android:name="alias_target" android:value="android.content.componentalias.tests.sub1/android.content.componentalias.tests.s.Target01" />
            <intent-filter><action android:name="com.android.intent.action.EXPERIMENTAL_IS_ALIAS" /></intent-filter>
            <intent-filter><action android:name="android.content.componentalias.tests.IS_ALIAS_01" /></intent-filter>
        </service>
        <service android:name=".s.Alias02" android:exported="true" android:enabled="true" >
            <meta-data android:name="alias_target" android:value="android.content.componentalias.tests.sub2/android.content.componentalias.tests.s.Target02" />
            <intent-filter><action android:name="com.android.intent.action.EXPERIMENTAL_IS_ALIAS" /></intent-filter>
            <intent-filter><action android:name="android.content.componentalias.tests.IS_ALIAS_02" /></intent-filter>
        </service>
        <service android:name=".s.Alias03" android:exported="true" android:enabled="true" >
            <meta-data android:name="alias_target" android:value="android.content.componentalias.tests.sub1/android.content.componentalias.tests.s.Target03" />
            <intent-filter><action android:name="com.android.intent.action.EXPERIMENTAL_IS_ALIAS" /></intent-filter>
            <intent-filter><action android:name="android.content.componentalias.tests.IS_ALIAS_03" /></intent-filter>
        </service>
        <service android:name=".s.Alias04" android:exported="true" android:enabled="true" >
            <meta-data android:name="alias_target" android:value="android.content.componentalias.tests.sub2/android.content.componentalias.tests.s.Target04" />
            <intent-filter><action android:name="com.android.intent.action.EXPERIMENTAL_IS_ALIAS" /></intent-filter>
            <intent-filter><action android:name="android.content.componentalias.tests.IS_ALIAS_04" /></intent-filter>
        </service>

        <receiver android:name=".b.Alias00" android:exported="true" android:enabled="true" >
            <meta-data android:name="alias_target" android:value="android.content.componentalias.tests/android.content.componentalias.tests.b.Target00" />
            <intent-filter><action android:name="com.android.intent.action.EXPERIMENTAL_IS_ALIAS" /></intent-filter>
            <intent-filter><action android:name="android.content.componentalias.tests.IS_RECEIVER_00" /></intent-filter>
            <intent-filter><action android:name="ACTION_BROADCAST" /></intent-filter>
        </receiver>
        <receiver android:name=".b.Alias01" android:exported="true" android:enabled="true" >
            <meta-data android:name="alias_target" android:value="android.content.componentalias.tests.sub1/android.content.componentalias.tests.b.Target01" />
            <intent-filter><action android:name="com.android.intent.action.EXPERIMENTAL_IS_ALIAS" /></intent-filter>
            <intent-filter><action android:name="android.content.componentalias.tests.IS_RECEIVER_01" /></intent-filter>
            <intent-filter><action android:name="ACTION_BROADCAST" /></intent-filter>
        </receiver>
        <receiver android:name=".b.Alias02" android:exported="true" android:enabled="true" >
            <meta-data android:name="alias_target" android:value="android.content.componentalias.tests.sub2/android.content.componentalias.tests.b.Target02" />
            <intent-filter><action android:name="com.android.intent.action.EXPERIMENTAL_IS_ALIAS" /></intent-filter>
            <intent-filter><action android:name="android.content.componentalias.tests.IS_RECEIVER_02" /></intent-filter>
            <intent-filter><action android:name="ACTION_BROADCAST" /></intent-filter>
        </receiver>
        <receiver android:name=".b.Alias03" android:exported="true" android:enabled="true" >
            <meta-data android:name="alias_target" android:value="android.content.componentalias.tests.sub1/android.content.componentalias.tests.b.Target03" />
            <intent-filter><action android:name="com.android.intent.action.EXPERIMENTAL_IS_ALIAS" /></intent-filter>
            <intent-filter><action android:name="android.content.componentalias.tests.IS_RECEIVER_03" /></intent-filter>
            <intent-filter><action android:name="ACTION_BROADCAST" /></intent-filter>
        </receiver>
        <receiver android:name=".b.Alias04" android:exported="true" android:enabled="true" >
            <meta-data android:name="alias_target" android:value="android.content.componentalias.tests.sub2/android.content.componentalias.tests.b.Target04" />
            <intent-filter><action android:name="com.android.intent.action.EXPERIMENTAL_IS_ALIAS" /></intent-filter>
            <intent-filter><action android:name="android.content.componentalias.tests.IS_RECEIVER_04" /></intent-filter>
            <intent-filter><action android:name="ACTION_BROADCAST" /></intent-filter>
        </receiver>
    </application>
</manifest>
Loading