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

Commit 27c4e658 authored by Chen Xu's avatar Chen Xu
Browse files

remove symbols from greylist

telephony-common is not intended to used by any apps and
being in boot class is not updatability friendly.
We are removing telephony-common from bootclass and apply
<uses-library> in manifest instead.
for apps targeting < R will auto load telephony-common lib
for app compatibility. For apos >=R, only allow usage for
phone UID.

Bug: 135955937
Test: Build
Change-Id: Ia318661546df6d8516328886e5cc0c54d5cfafe6
parent 2c833c2b
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -1174,8 +1174,6 @@ Lcom/android/internal/statusbar/IStatusBar$Stub;->asInterface(Landroid/os/IBinde
Lcom/android/internal/statusbar/IStatusBarService$Stub;-><init>()V
Lcom/android/internal/statusbar/IStatusBarService$Stub;->asInterface(Landroid/os/IBinder;)Lcom/android/internal/statusbar/IStatusBarService;
Lcom/android/internal/telecom/ITelecomService$Stub;->asInterface(Landroid/os/IBinder;)Lcom/android/internal/telecom/ITelecomService;
Lcom/android/internal/telephony/IIccPhoneBook$Stub$Proxy;->mRemote:Landroid/os/IBinder;
Lcom/android/internal/telephony/IIccPhoneBook$Stub;->asInterface(Landroid/os/IBinder;)Lcom/android/internal/telephony/IIccPhoneBook;
Lcom/android/internal/telephony/IMms$Stub;->asInterface(Landroid/os/IBinder;)Lcom/android/internal/telephony/IMms;
Lcom/android/internal/telephony/IPhoneStateListener$Stub;->asInterface(Landroid/os/IBinder;)Lcom/android/internal/telephony/IPhoneStateListener;
Lcom/android/internal/telephony/IPhoneSubInfo$Stub$Proxy;-><init>(Landroid/os/IBinder;)V
@@ -1183,7 +1181,6 @@ Lcom/android/internal/telephony/IPhoneSubInfo$Stub;->asInterface(Landroid/os/IBi
Lcom/android/internal/telephony/IPhoneSubInfo$Stub;->TRANSACTION_getDeviceId:I
Lcom/android/internal/telephony/ISms$Stub;-><init>()V
Lcom/android/internal/telephony/ISms$Stub;->asInterface(Landroid/os/IBinder;)Lcom/android/internal/telephony/ISms;
Lcom/android/internal/telephony/ISub$Stub$Proxy;-><init>(Landroid/os/IBinder;)V
Lcom/android/internal/telephony/ISub$Stub;->asInterface(Landroid/os/IBinder;)Lcom/android/internal/telephony/ISub;
Lcom/android/internal/telephony/ITelephony$Stub$Proxy;-><init>(Landroid/os/IBinder;)V
Lcom/android/internal/telephony/ITelephony$Stub$Proxy;->mRemote:Landroid/os/IBinder;
@@ -1207,5 +1204,4 @@ Lcom/android/server/net/BaseNetworkObserver;-><init>()V
Lcom/android/server/ResettableTimeout$T;-><init>(Lcom/android/server/ResettableTimeout;)V
Lcom/google/android/gles_jni/EGLImpl;-><init>()V
Lcom/google/android/gles_jni/GLImpl;-><init>()V
Lcom/google/android/mms/pdu/PduParser;->$assertionsDisabled:Z
Lcom/google/android/util/AbstractMessageParser$Token$Type;->values()[Lcom/google/android/util/AbstractMessageParser$Token$Type;
+82 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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 android.content.pm;

import static android.content.pm.SharedLibraryNames.ANDROID_TELEPHONY_COMMON;


import com.android.internal.compat.IPlatformCompat;
import android.compat.annotation.ChangeId;
import android.compat.annotation.EnabledAfter;
import android.content.pm.PackageParser.Package;

import android.os.Build.VERSION_CODES;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;

/**
 * Updates a package to ensure that
 * <ul>
 * <li> if apps have target SDK < R, then telephony-common library is included by default to
 * their class path. Even without <uses-library>.</li>
 * <li> if apps with target SDK level >= R && have special permission (or Phone UID):
 * apply <uses-library> on telephony-common should work.</li>
 * <li> Otherwise not allow to use the lib.
 * See {@link PackageSharedLibraryUpdater#removeLibrary(Package, String)}.</li>
 * </ul>
 *
 * @hide
 */
@VisibleForTesting
public class AndroidTelephonyCommonUpdater extends PackageSharedLibraryUpdater {

    private static final String TAG = AndroidTelephonyCommonUpdater.class.getSimpleName();
    /**
     * Restrict telephony-common lib for apps having target SDK >= R
     */
    @ChangeId
    @EnabledAfter(targetSdkVersion = VERSION_CODES.Q)
    static final long RESTRICT_TELEPHONY_COMMON_CHANGE_ID = 139318877L;

    private static boolean apkTargetsApiLevelLessThanROrCurrent(Package pkg) {
        boolean shouldRestrict = false;
        try {
            IBinder b = ServiceManager.getService("platform_compat");
            IPlatformCompat platformCompat = IPlatformCompat.Stub.asInterface(b);
            shouldRestrict = platformCompat.isChangeEnabled(RESTRICT_TELEPHONY_COMMON_CHANGE_ID,
                pkg.applicationInfo);
        } catch (RemoteException ex) {
            Log.e(TAG, ex.getMessage());
        }
        // TODO(b/139318877): remove version check for CUR_DEVELOPEMENT after clean up work.
        return !shouldRestrict
            || pkg.applicationInfo.targetSdkVersion == VERSION_CODES.CUR_DEVELOPMENT;
    }

    @Override
    public void updatePackage(Package pkg) {
        // for apps with targetSDKVersion < R include the library for backward compatibility.
        if (apkTargetsApiLevelLessThanROrCurrent(pkg)) {
            prefixRequiredLibrary(pkg, ANDROID_TELEPHONY_COMMON);
        } else if (pkg.mSharedUserId == null || !pkg.mSharedUserId.equals("android.uid.phone")) {
            // if apps target >= R
            removeLibrary(pkg, ANDROID_TELEPHONY_COMMON);
        }
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -51,6 +51,8 @@ public class PackageBackwardCompatibility extends PackageSharedLibraryUpdater {

        packageUpdaters.add(new AndroidHidlUpdater());

        packageUpdaters.add(new AndroidTelephonyCommonUpdater());

        // Add this before adding AndroidTestBaseUpdater so that android.test.base comes before
        // android.test.mock.
        packageUpdaters.add(new AndroidTestRunnerSplitUpdater());
+2 −0
Original line number Diff line number Diff line
@@ -33,4 +33,6 @@ public class SharedLibraryNames {
    static final String ANDROID_TEST_RUNNER = "android.test.runner";

    public static final String ORG_APACHE_HTTP_LEGACY = "org.apache.http.legacy";

    public static final String ANDROID_TELEPHONY_COMMON = "telephony-common";
}
+140 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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 android.content.pm;

import static android.content.pm.PackageBuilder.builder;
import static android.content.pm.SharedLibraryNames.ANDROID_HIDL_BASE;
import static android.content.pm.SharedLibraryNames.ANDROID_HIDL_MANAGER;
import static android.content.pm.SharedLibraryNames.ANDROID_TELEPHONY_COMMON;

import android.os.Build;
import androidx.test.filters.SmallTest;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/**
 * Test for {@link AndroidHidlUpdater}
 */
@SmallTest
@RunWith(JUnit4.class)
public class AndroidTelephonyCommonUpdaterTest extends PackageSharedLibraryUpdaterTest {

    private static final String OTHER_LIBRARY = "other.library";
    private static final String PHONE_UID = "android.uid.phone";

    @Test
    public void targeted_at_Q() {
        PackageBuilder before = builder()
                .targetSdkVersion(Build.VERSION_CODES.Q);

        PackageBuilder after = builder().targetSdkVersion(Build.VERSION_CODES.Q)
            .requiredLibraries(ANDROID_TELEPHONY_COMMON);

        // Should add telephony-common libraries
        checkBackwardsCompatibility(before, after);
    }

    @Test
    public void targeted_at_Q_phoneUID() {
        PackageBuilder before = builder().setSharedUid(PHONE_UID)
                .targetSdkVersion(Build.VERSION_CODES.Q);

        // Should add telephony-common libraries
        PackageBuilder after = builder().setSharedUid(PHONE_UID)
                .targetSdkVersion(Build.VERSION_CODES.Q)
                .requiredLibraries(ANDROID_TELEPHONY_COMMON);

        checkBackwardsCompatibility(before, after);
    }

    @Test
    public void targeted_at_Q_not_empty_usesLibraries() {
        PackageBuilder before = builder()
                .targetSdkVersion(Build.VERSION_CODES.Q)
                .requiredLibraries(OTHER_LIBRARY);

        // no change
        checkBackwardsCompatibility(before, before);
    }

    @Test
    public void targeted_at_Q_not_empty_usesLibraries_phoneUID() {
        PackageBuilder before = builder().setSharedUid(PHONE_UID)
                .targetSdkVersion(Build.VERSION_CODES.Q)
                .requiredLibraries(OTHER_LIBRARY);

        // The telephony-common jars should be added at the start of the list because it
        // is not on the bootclasspath and the package targets pre-R.
        PackageBuilder after = builder().setSharedUid(PHONE_UID)
                .targetSdkVersion(Build.VERSION_CODES.Q)
                .requiredLibraries(ANDROID_TELEPHONY_COMMON, OTHER_LIBRARY);

        checkBackwardsCompatibility(before, after);
    }

    @Test
    public void targeted_at_R_in_usesLibraries() {
        PackageBuilder before = builder()
                .targetSdkVersion(Build.VERSION_CODES.Q + 1)
                .requiredLibraries(ANDROID_TELEPHONY_COMMON);

        PackageBuilder after = builder()
                .targetSdkVersion(Build.VERSION_CODES.Q + 1);

        // Libraries are removed because they are not available for apps target >= R and not run
        // on phone-uid
        checkBackwardsCompatibility(before, after);
    }

    @Test
    public void targeted_at_Q_in_usesLibraries() {
        PackageBuilder before = builder().asSystemApp()
                .targetSdkVersion(Build.VERSION_CODES.Q)
                .requiredLibraries(ANDROID_TELEPHONY_COMMON);

        // No change is required because the package explicitly requests the telephony libraries
        // and is targeted at the current version so does not need backwards compatibility.
        checkBackwardsCompatibility(before, before);
    }


    @Test
    public void targeted_at_R_in_usesOptionalLibraries() {
        PackageBuilder before = builder().targetSdkVersion(Build.VERSION_CODES.Q + 1)
            .optionalLibraries(ANDROID_TELEPHONY_COMMON);

        // Dependency is removed, it is not available.
        PackageBuilder after = builder().targetSdkVersion(Build.VERSION_CODES.Q + 1);

        // Libraries are removed because they are not available for apps targeting Q+
        checkBackwardsCompatibility(before, after);
    }

    @Test
    public void targeted_at_R() {
        PackageBuilder before = builder()
            .targetSdkVersion(Build.VERSION_CODES.Q + 1);

        // no change
        checkBackwardsCompatibility(before, before);
    }

    private void checkBackwardsCompatibility(PackageBuilder before, PackageBuilder after) {
        checkBackwardsCompatibility(before, after, AndroidTelephonyCommonUpdater::new);
    }
}
Loading