diff options
30 files changed, 615 insertions, 185 deletions
diff --git a/Android.mk b/Android.mk index c58f7af1d7d5..9bda2dc6d69a 100644 --- a/Android.mk +++ b/Android.mk @@ -32,27 +32,6 @@ ifneq ($(ANDROID_BUILD_EMBEDDED),true) # ============================================================ include $(CLEAR_VARS) -aidl_parcelables := -define stubs-to-aidl-parcelables - gen := $(TARGET_OUT_COMMON_INTERMEDIATES)/$1.aidl - aidl_parcelables += $$(gen) - $$(gen): $(call java-lib-header-files,$1) $(HOST_OUT_EXECUTABLES)/sdkparcelables - @echo Extract SDK parcelables: $$@ - rm -f $$@ - $(HOST_OUT_EXECUTABLES)/sdkparcelables $$< $$@ -endef - -$(foreach stubs,android_stubs_current android_test_stubs_current android_system_stubs_current,\ - $(eval $(call stubs-to-aidl-parcelables,$(stubs)))) - -gen := $(TARGET_OUT_COMMON_INTERMEDIATES)/framework.aidl -.KATI_RESTAT: $(gen) -$(gen): $(aidl_parcelables) - @echo Combining SDK parcelables: $@ - rm -f $@.tmp - cat $^ | sort -u > $@.tmp - $(call commit-change-for-toc,$@) - # This is used by ide.mk as the list of source files that are # always included. INTERNAL_SDK_SOURCE_DIRS := $(addprefix $(LOCAL_PATH)/,$(dirs_to_document)) diff --git a/api/current.txt b/api/current.txt index 4dcba8348d8c..2417d8ef1924 100755 --- a/api/current.txt +++ b/api/current.txt @@ -8734,8 +8734,8 @@ package android.bluetooth.le { method public android.bluetooth.le.ScanFilter.Builder setManufacturerData(int, byte[], byte[]); method public android.bluetooth.le.ScanFilter.Builder setServiceData(android.os.ParcelUuid, byte[]); method public android.bluetooth.le.ScanFilter.Builder setServiceData(android.os.ParcelUuid, byte[], byte[]); - method public android.bluetooth.le.ScanFilter.Builder setServiceSolicitationUuid(android.os.ParcelUuid); - method public android.bluetooth.le.ScanFilter.Builder setServiceSolicitationUuid(android.os.ParcelUuid, android.os.ParcelUuid); + method @NonNull public android.bluetooth.le.ScanFilter.Builder setServiceSolicitationUuid(@Nullable android.os.ParcelUuid); + method @NonNull public android.bluetooth.le.ScanFilter.Builder setServiceSolicitationUuid(@Nullable android.os.ParcelUuid, @Nullable android.os.ParcelUuid); method public android.bluetooth.le.ScanFilter.Builder setServiceUuid(android.os.ParcelUuid); method public android.bluetooth.le.ScanFilter.Builder setServiceUuid(android.os.ParcelUuid, android.os.ParcelUuid); } diff --git a/api/test-current.txt b/api/test-current.txt index dc5ff8f229c2..cb9ff493c546 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -923,6 +923,7 @@ package android.net.util { package android.os { public static class Build.VERSION { + field public static final String[] ACTIVE_CODENAMES; field public static final int FIRST_SDK_INT; field public static final int RESOURCES_SDK_INT; } diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index f453289b4bc5..d9c82ea31537 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -1003,9 +1003,8 @@ public final class ActivityThread extends ClientTransactionHandler { } public void updateHttpProxy() { - final ConnectivityManager cm = ConnectivityManager.from( + ActivityThread.updateHttpProxy( getApplication() != null ? getApplication() : getSystemContext()); - Proxy.setHttpProxySystemProperty(cm.getDefaultProxy()); } public void processInBackground() { @@ -6690,6 +6689,11 @@ public final class ActivityThread extends ClientTransactionHandler { return thread; } + public static void updateHttpProxy(@NonNull Context context) { + final ConnectivityManager cm = ConnectivityManager.from(context); + Proxy.setHttpProxySystemProperty(cm.getDefaultProxy()); + } + @UnsupportedAppUsage public final void installSystemProviders(List<ProviderInfo> providers) { if (providers != null) { diff --git a/core/java/android/bluetooth/le/ScanFilter.java b/core/java/android/bluetooth/le/ScanFilter.java index c5d435b76139..66d1da8909cd 100644 --- a/core/java/android/bluetooth/le/ScanFilter.java +++ b/core/java/android/bluetooth/le/ScanFilter.java @@ -16,6 +16,7 @@ package android.bluetooth.le; +import android.annotation.NonNull; import android.annotation.Nullable; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; @@ -586,7 +587,8 @@ public final class ScanFilter implements Parcelable { /** * Set filter on service solicitation uuid. */ - public Builder setServiceSolicitationUuid(ParcelUuid serviceSolicitationUuid) { + public @NonNull Builder setServiceSolicitationUuid( + @Nullable ParcelUuid serviceSolicitationUuid) { mServiceSolicitationUuid = serviceSolicitationUuid; return this; } @@ -601,8 +603,9 @@ public final class ScanFilter implements Parcelable { * @throws IllegalArgumentException If {@code serviceSolicitationUuid} is {@code null} but * {@code serviceSolicitationUuidMask} is not {@code null}. */ - public Builder setServiceSolicitationUuid(ParcelUuid serviceSolicitationUuid, - ParcelUuid solicitationUuidMask) { + public @NonNull Builder setServiceSolicitationUuid( + @Nullable ParcelUuid serviceSolicitationUuid, + @Nullable ParcelUuid solicitationUuidMask) { if (mServiceSolicitationUuidMask != null && mServiceSolicitationUuid == null) { throw new IllegalArgumentException( "SolicitationUuid is null while SolicitationUuidMask is not null!"); diff --git a/core/java/android/os/Build.java b/core/java/android/os/Build.java index 1c319fb4ea36..d3bed02a4b47 100755 --- a/core/java/android/os/Build.java +++ b/core/java/android/os/Build.java @@ -287,6 +287,7 @@ public class Build { /** * @hide */ + @TestApi @UnsupportedAppUsage public static final String[] ACTIVE_CODENAMES = "REL".equals(ALL_CODENAMES[0]) ? new String[0] : ALL_CODENAMES; diff --git a/core/java/android/os/GraphicsEnvironment.java b/core/java/android/os/GraphicsEnvironment.java index d46cf3cb974a..1aaee18914a2 100644 --- a/core/java/android/os/GraphicsEnvironment.java +++ b/core/java/android/os/GraphicsEnvironment.java @@ -20,24 +20,16 @@ import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.res.AssetManager; -import android.gamedriver.GameDriverProto.Blacklist; -import android.gamedriver.GameDriverProto.Blacklists; import android.opengl.EGL14; import android.os.Build; import android.os.SystemProperties; import android.provider.Settings; -import android.util.Base64; import android.util.Log; -import com.android.framework.protobuf.InvalidProtocolBufferException; - import dalvik.system.VMRuntime; -import java.io.BufferedReader; import java.io.File; import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -57,9 +49,7 @@ public class GraphicsEnvironment { private static final boolean DEBUG = false; private static final String TAG = "GraphicsEnvironment"; private static final String PROPERTY_GFX_DRIVER = "ro.gfx.driver.0"; - private static final String GAME_DRIVER_WHITELIST_FILENAME = "whitelist.txt"; - private static final String GAME_DRIVER_BLACKLIST_FLAG = "blacklist"; - private static final int BASE64_FLAGS = Base64.NO_PADDING | Base64.NO_WRAP; + private static final String GAME_DRIVER_WHITELIST_ALL = "*"; private ClassLoader mClassLoader; private String mLayerPath; @@ -108,15 +98,15 @@ public class GraphicsEnvironment { if (isDebuggable(context)) { - int enable = Settings.Global.getInt(context.getContentResolver(), - Settings.Global.ENABLE_GPU_DEBUG_LAYERS, 0); + final int enable = Settings.Global.getInt(context.getContentResolver(), + Settings.Global.ENABLE_GPU_DEBUG_LAYERS, 0); if (enable != 0) { - String gpuDebugApp = Settings.Global.getString(context.getContentResolver(), - Settings.Global.GPU_DEBUG_APP); + final String gpuDebugApp = Settings.Global.getString(context.getContentResolver(), + Settings.Global.GPU_DEBUG_APP); - String packageName = context.getPackageName(); + final String packageName = context.getPackageName(); if ((gpuDebugApp != null && packageName != null) && (!gpuDebugApp.isEmpty() && !packageName.isEmpty()) @@ -148,7 +138,7 @@ public class GraphicsEnvironment { private static List<String> getGlobalSettingsString(Bundle bundle, String globalSetting) { List<String> valueList = null; - String settingsValue = bundle.getString(globalSetting); + final String settingsValue = bundle.getString(globalSetting); if (settingsValue != null) { valueList = new ArrayList<>(Arrays.asList(settingsValue.split(","))); @@ -163,12 +153,12 @@ public class GraphicsEnvironment { * Choose whether the current process should use the builtin or an updated driver. */ private static void chooseDriver(Context context, Bundle coreSettings) { - String driverPackageName = SystemProperties.get(PROPERTY_GFX_DRIVER); + final String driverPackageName = SystemProperties.get(PROPERTY_GFX_DRIVER); if (driverPackageName == null || driverPackageName.isEmpty()) { return; } - ApplicationInfo driverInfo; + final ApplicationInfo driverInfo; try { driverInfo = context.getPackageManager().getApplicationInfo(driverPackageName, PackageManager.MATCH_SYSTEM_ONLY); @@ -189,7 +179,7 @@ public class GraphicsEnvironment { // To minimize risk of driver updates crippling the device beyond user repair, never use an // updated driver for privileged or non-updated system apps. Presumably pre-installed apps // were tested thoroughly with the pre-installed driver. - ApplicationInfo ai = context.getApplicationInfo(); + final ApplicationInfo ai = context.getApplicationInfo(); if (ai.isPrivilegedApp() || (ai.isSystemApp() && !ai.isUpdatedSystemApp())) { if (DEBUG) Log.v(TAG, "ignoring driver package for privileged/non-updated system app"); return; @@ -199,7 +189,7 @@ public class GraphicsEnvironment { // 0: Default (Invalid values fallback to default as well) // 1: All apps use Game Driver // 2: All apps use system graphics driver - int gameDriverAllApps = coreSettings.getInt(Settings.Global.GAME_DRIVER_ALL_APPS, 0); + final int gameDriverAllApps = coreSettings.getInt(Settings.Global.GAME_DRIVER_ALL_APPS, 0); if (gameDriverAllApps == 2) { if (DEBUG) { Log.w(TAG, "Game Driver is turned off on this device"); @@ -216,49 +206,29 @@ public class GraphicsEnvironment { } return; } - boolean isOptIn = + final boolean isOptIn = getGlobalSettingsString(coreSettings, Settings.Global.GAME_DRIVER_OPT_IN_APPS) .contains(ai.packageName); - - if (!isOptIn && !onWhitelist(context, driverPackageName, ai.packageName)) { + final List<String> whitelist = getGlobalSettingsString(coreSettings, + Settings.Global.GAME_DRIVER_WHITELIST); + if (!isOptIn && whitelist.indexOf(GAME_DRIVER_WHITELIST_ALL) != 0 + && !whitelist.contains(ai.packageName)) { if (DEBUG) { Log.w(TAG, ai.packageName + " is not on the whitelist."); } return; } - if (!isOptIn) { - // At this point, the application is on the whitelist only, check whether it's - // on the blacklist, terminate early when it's on the blacklist. - try { - // TODO(b/121350991) Switch to DeviceConfig with property listener. - String base64String = - coreSettings.getString(Settings.Global.GAME_DRIVER_BLACKLIST); - if (base64String != null && !base64String.isEmpty()) { - Blacklists blacklistsProto = Blacklists.parseFrom( - Base64.decode(base64String, BASE64_FLAGS)); - List<Blacklist> blacklists = blacklistsProto.getBlacklistsList(); - long driverVersionCode = driverInfo.longVersionCode; - for (Blacklist blacklist : blacklists) { - if (blacklist.getVersionCode() == driverVersionCode) { - for (String packageName : blacklist.getPackageNamesList()) { - if (packageName == ai.packageName) { - return; - } - } - break; - } - } - } - } catch (InvalidProtocolBufferException e) { - if (DEBUG) { - Log.w(TAG, "Can't parse blacklist, skip and continue..."); - } - } + // If the application is not opted-in and check whether it's on the blacklist, + // terminate early if it's on the blacklist and fallback to system driver. + if (!isOptIn + && getGlobalSettingsString(coreSettings, Settings.Global.GAME_DRIVER_BLACKLIST) + .contains(ai.packageName)) { + return; } } - String abi = chooseAbi(driverInfo); + final String abi = chooseAbi(driverInfo); if (abi == null) { if (DEBUG) { // This is the normal case for the pre-installed empty driver package, don't spam @@ -269,16 +239,23 @@ public class GraphicsEnvironment { return; } - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); sb.append(driverInfo.nativeLibraryDir) .append(File.pathSeparator); sb.append(driverInfo.sourceDir) .append("!/lib/") .append(abi); - String paths = sb.toString(); + final String paths = sb.toString(); + + final String sphalLibraries = + coreSettings.getString(Settings.Global.GAME_DRIVER_SPHAL_LIBRARIES); - if (DEBUG) Log.v(TAG, "gfx driver package libs: " + paths); - setDriverPath(paths); + if (DEBUG) { + Log.v(TAG, + "gfx driver package search path: " + paths + + ", required sphal libraries: " + sphalLibraries); + } + setDriverPathAndSphalLibraries(paths, sphalLibraries); } /** @@ -292,7 +269,7 @@ public class GraphicsEnvironment { * Should only be called after chooseDriver(). */ public static void earlyInitEGL() { - Thread eglInitThread = new Thread( + final Thread eglInitThread = new Thread( () -> { EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY); }, @@ -301,7 +278,7 @@ public class GraphicsEnvironment { } private static String chooseAbi(ApplicationInfo ai) { - String isa = VMRuntime.getCurrentInstructionSet(); + final String isa = VMRuntime.getCurrentInstructionSet(); if (ai.primaryCpuAbi != null && isa.equals(VMRuntime.getInstructionSet(ai.primaryCpuAbi))) { return ai.primaryCpuAbi; @@ -313,32 +290,7 @@ public class GraphicsEnvironment { return null; } - private static boolean onWhitelist(Context context, String driverPackageName, - String applicationPackageName) { - try { - Context driverContext = context.createPackageContext(driverPackageName, - Context.CONTEXT_RESTRICTED); - AssetManager assets = driverContext.getAssets(); - InputStream stream = assets.open(GAME_DRIVER_WHITELIST_FILENAME); - BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); - for (String packageName; (packageName = reader.readLine()) != null; ) { - if (packageName.equals(applicationPackageName)) { - return true; - } - } - } catch (PackageManager.NameNotFoundException e) { - if (DEBUG) { - Log.w(TAG, "driver package '" + driverPackageName + "' not installed"); - } - } catch (IOException e) { - if (DEBUG) { - Log.w(TAG, "Failed to load whitelist driver package, abort."); - } - } - return false; - } - private static native void setLayerPaths(ClassLoader classLoader, String layerPaths); private static native void setDebugLayers(String layers); - private static native void setDriverPath(String path); + private static native void setDriverPathAndSphalLibraries(String path, String sphalLibraries); } diff --git a/core/java/android/provider/CallLog.java b/core/java/android/provider/CallLog.java index ef28f07e817f..0827fd6e725e 100644 --- a/core/java/android/provider/CallLog.java +++ b/core/java/android/provider/CallLog.java @@ -967,6 +967,23 @@ public class CallLog { // spam the call log with its own entries, causing entries from Telephony to be // removed. final Uri result = resolver.insert(uri, values); + if (result != null) { + String lastPathSegment = result.getLastPathSegment(); + // When inserting into the call log, if ContentProvider#insert detect an appops + // denial a non-null "silent rejection" URI is returned which ends in 0. + // Example: content://call_log/calls/0 + // The 0 in the last part of the path indicates a fake call id of 0. + // A denial when logging calls from the platform is bad; there is no other + // logging to indicate that this has happened so we will check for that scenario + // here and log a warning so we have a hint as to what is going on. + if (lastPathSegment != null && lastPathSegment.equals("0")) { + Log.w(LOG_TAG, "Failed to insert into call log due to appops denial;" + + " resultUri=" + result); + } + } else { + Log.w(LOG_TAG, "Failed to insert into call log; null result uri."); + } + if (values.containsKey(PHONE_ACCOUNT_ID) && !TextUtils.isEmpty(values.getAsString(PHONE_ACCOUNT_ID)) && values.containsKey(PHONE_ACCOUNT_COMPONENT_NAME) diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index a0e4d0dcb90e..f98641d3ddc7 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -11475,6 +11475,12 @@ public final class Settings { public static final String GAME_DRIVER_BLACKLIST = "game_driver_blacklist"; /** + * List of blacklists, each blacklist is a blacklist for a specific version of Game Driver. + * @hide + */ + public static final String GAME_DRIVER_BLACKLISTS = "game_driver_blacklists"; + + /** * Apps on the whitelist that are allowed to use Game Driver. * The string is a list of application package names, seperated by comma. * i.e. <apk1>,<apk2>,...,<apkN> @@ -11483,6 +11489,14 @@ public final class Settings { public static final String GAME_DRIVER_WHITELIST = "game_driver_whitelist"; /** + * List of libraries in sphal accessible by Game Driver + * The string is a list of library names, separated by colon. + * i.e. <lib1>:<lib2>:...:<libN> + * @hide + */ + public static final String GAME_DRIVER_SPHAL_LIBRARIES = "game_driver_sphal_libraries"; + + /** * Ordered GPU debug layer list * i.e. <layer1>:<layer2>:...:<layerN> * @hide diff --git a/core/jni/android_os_GraphicsEnvironment.cpp b/core/jni/android_os_GraphicsEnvironment.cpp index dfa5de6b65c6..b95d500212d4 100644 --- a/core/jni/android_os_GraphicsEnvironment.cpp +++ b/core/jni/android_os_GraphicsEnvironment.cpp @@ -23,9 +23,12 @@ namespace { -void setDriverPath(JNIEnv* env, jobject clazz, jstring path) { +void setDriverPathAndSphalLibraries_native(JNIEnv* env, jobject clazz, jstring path, + jstring sphalLibraries) { ScopedUtfChars pathChars(env, path); - android::GraphicsEnv::getInstance().setDriverPath(pathChars.c_str()); + ScopedUtfChars sphalLibrariesChars(env, sphalLibraries); + android::GraphicsEnv::getInstance().setDriverPathAndSphalLibraries(pathChars.c_str(), + sphalLibrariesChars.c_str()); } void setLayerPaths_native(JNIEnv* env, jobject clazz, jobject classLoader, jstring layerPaths) { @@ -43,7 +46,7 @@ void setDebugLayers_native(JNIEnv* env, jobject clazz, jstring layers) { } const JNINativeMethod g_methods[] = { - { "setDriverPath", "(Ljava/lang/String;)V", reinterpret_cast<void*>(setDriverPath) }, + { "setDriverPathAndSphalLibraries", "(Ljava/lang/String;Ljava/lang/String;)V", reinterpret_cast<void*>(setDriverPathAndSphalLibraries_native) }, { "setLayerPaths", "(Ljava/lang/ClassLoader;Ljava/lang/String;)V", reinterpret_cast<void*>(setLayerPaths_native) }, { "setDebugLayers", "(Ljava/lang/String;)V", reinterpret_cast<void*>(setDebugLayers_native) }, }; diff --git a/core/proto/android/providers/settings/global.proto b/core/proto/android/providers/settings/global.proto index 5aa3992d73f0..a44ec9a911be 100644 --- a/core/proto/android/providers/settings/global.proto +++ b/core/proto/android/providers/settings/global.proto @@ -399,6 +399,11 @@ message GlobalSettingsProto { optional SettingProto game_driver_blacklist = 11; // Game Driver - List of Apps that are allowed to use Game Driver optional SettingProto game_driver_whitelist = 12; + // Game Driver - List of blacklists, each blacklist is a blacklist for + // a specific Game Driver version + optional SettingProto game_driver_blacklists = 14; + // Game Driver - List of libraries in sphal accessible by Game Driver + optional SettingProto game_driver_sphal_libraries = 16; } optional Gpu gpu = 59; diff --git a/core/tests/coretests/src/android/provider/SettingsBackupTest.java b/core/tests/coretests/src/android/provider/SettingsBackupTest.java index c1664087fb31..76356ed572c7 100644 --- a/core/tests/coretests/src/android/provider/SettingsBackupTest.java +++ b/core/tests/coretests/src/android/provider/SettingsBackupTest.java @@ -447,8 +447,10 @@ public class SettingsBackupTest { Settings.Global.GAME_DRIVER_ALL_APPS, Settings.Global.GAME_DRIVER_OPT_IN_APPS, Settings.Global.GAME_DRIVER_OPT_OUT_APPS, + Settings.Global.GAME_DRIVER_BLACKLISTS, Settings.Global.GAME_DRIVER_BLACKLIST, Settings.Global.GAME_DRIVER_WHITELIST, + Settings.Global.GAME_DRIVER_SPHAL_LIBRARIES, Settings.Global.ENABLE_GNSS_RAW_MEAS_FULL_TRACKING, Settings.Global.INSTALL_CARRIER_APP_NOTIFICATION_PERSISTENT, Settings.Global.INSTALL_CARRIER_APP_NOTIFICATION_SLEEP_MILLIS, diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java index 43c1a267468e..c60e352e9960 100644 --- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java +++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java @@ -662,6 +662,12 @@ class SettingsProtoDumpUtil { dumpSetting(s, p, Settings.Global.GAME_DRIVER_WHITELIST, GlobalSettingsProto.Gpu.GAME_DRIVER_WHITELIST); + dumpSetting(s, p, + Settings.Global.GAME_DRIVER_BLACKLISTS, + GlobalSettingsProto.Gpu.GAME_DRIVER_BLACKLISTS); + dumpSetting(s, p, + Settings.Global.GAME_DRIVER_SPHAL_LIBRARIES, + GlobalSettingsProto.Gpu.GAME_DRIVER_SPHAL_LIBRARIES); p.end(gpuToken); final long hdmiToken = p.start(GlobalSettingsProto.HDMI); diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index e18f3740a969..5ebd17360961 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -318,7 +318,6 @@ import android.location.LocationManager; import android.media.audiofx.AudioEffect; import android.metrics.LogMaker; import android.net.Proxy; -import android.net.ProxyInfo; import android.net.Uri; import android.os.BatteryStats; import android.os.Binder; @@ -2252,21 +2251,25 @@ public class ActivityManagerService extends IActivityManager.Stub } } break; case UPDATE_HTTP_PROXY_MSG: { + // Update the HTTP proxy for each application thread. synchronized (ActivityManagerService.this) { for (int i = mLruProcesses.size() - 1 ; i >= 0 ; i--) { ProcessRecord r = mLruProcesses.get(i); // Don't dispatch to isolated processes as they can't access - // ConnectivityManager and don't have network privileges anyway. - if (r.thread != null && !r.isolated) { + // ConnectivityManager and don't have network privileges anyway. Exclude + // system server and update it separately outside the AMS lock, to avoid + // deadlock with Connectivity Service. + if (r.pid != MY_PID && r.thread != null && !r.isolated) { try { r.thread.updateHttpProxy(); } catch (RemoteException ex) { - Slog.w(TAG, "Failed to update http proxy for: " + - r.info.processName); + Slog.w(TAG, "Failed to update http proxy for: " + + r.info.processName); } } } } + ActivityThread.updateHttpProxy(mContext); } break; case PROC_START_TIMEOUT_MSG: { ProcessRecord app = (ProcessRecord)msg.obj; @@ -2607,7 +2610,7 @@ public class ActivityManagerService extends IActivityManager.Stub } break; } } - }; + } static final int COLLECT_PSS_BG_MSG = 1; diff --git a/services/core/java/com/android/server/am/CoreSettingsObserver.java b/services/core/java/com/android/server/am/CoreSettingsObserver.java index 75da9b54c662..9ff47e0dc0b4 100644 --- a/services/core/java/com/android/server/am/CoreSettingsObserver.java +++ b/services/core/java/com/android/server/am/CoreSettingsObserver.java @@ -60,6 +60,8 @@ final class CoreSettingsObserver extends ContentObserver { sGlobalSettingToTypeMap.put(Settings.Global.GAME_DRIVER_OPT_OUT_APPS, String.class); sGlobalSettingToTypeMap.put(Settings.Global.GAME_DRIVER_BLACKLIST, String.class); sGlobalSettingToTypeMap.put(Settings.Global.GAME_DRIVER_WHITELIST, String.class); + sGlobalSettingToTypeMap.put(Settings.Global.GAME_DRIVER_BLACKLISTS, String.class); + sGlobalSettingToTypeMap.put(Settings.Global.GAME_DRIVER_SPHAL_LIBRARIES, String.class); // add other global settings here... } diff --git a/services/core/java/com/android/server/gpu/GpuService.java b/services/core/java/com/android/server/gpu/GpuService.java new file mode 100644 index 000000000000..647727f795da --- /dev/null +++ b/services/core/java/com/android/server/gpu/GpuService.java @@ -0,0 +1,274 @@ +/* + * Copyright 2019 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.server.gpu; + +import static android.content.Intent.ACTION_PACKAGE_ADDED; +import static android.content.Intent.ACTION_PACKAGE_CHANGED; +import static android.content.Intent.ACTION_PACKAGE_REMOVED; + +import android.annotation.NonNull; +import android.content.BroadcastReceiver; +import android.content.ContentResolver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; +import android.database.ContentObserver; +import android.gamedriver.GameDriverProto.Blacklist; +import android.gamedriver.GameDriverProto.Blacklists; +import android.net.Uri; +import android.os.Build; +import android.os.Handler; +import android.os.SystemProperties; +import android.os.UserHandle; +import android.provider.Settings; +import android.util.Base64; +import android.util.Slog; + +import com.android.framework.protobuf.InvalidProtocolBufferException; +import com.android.internal.annotations.GuardedBy; +import com.android.server.SystemService; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + +/** + * Service to manage GPU related features. + * + * <p>GPU service is a core service that monitors, coordinates all GPU related features, + * as well as collect metrics about the GPU and GPU driver.</p> + */ +public class GpuService extends SystemService { + public static final String TAG = "GpuService"; + public static final boolean DEBUG = false; + + private static final String PROPERTY_GFX_DRIVER = "ro.gfx.driver.0"; + private static final String GAME_DRIVER_WHITELIST_FILENAME = "whitelist.txt"; + private static final String GAME_DRIVER_SPHAL_LIBRARIES_FILENAME = "sphal_libraries.txt"; + private static final int BASE64_FLAGS = Base64.NO_PADDING | Base64.NO_WRAP; + + private final Context mContext; + private final String mDriverPackageName; + private final PackageManager mPackageManager; + private final Object mLock = new Object(); + private ContentResolver mContentResolver; + private long mGameDriverVersionCode; + private SettingsObserver mSettingsObserver; + @GuardedBy("mLock") + private Blacklists mBlacklists; + + public GpuService(Context context) { + super(context); + + mContext = context; + mDriverPackageName = SystemProperties.get(PROPERTY_GFX_DRIVER); + mGameDriverVersionCode = -1; + mPackageManager = context.getPackageManager(); + if (mDriverPackageName != null && !mDriverPackageName.isEmpty()) { + final IntentFilter packageFilter = new IntentFilter(); + packageFilter.addAction(ACTION_PACKAGE_ADDED); + packageFilter.addAction(ACTION_PACKAGE_CHANGED); + packageFilter.addAction(ACTION_PACKAGE_REMOVED); + packageFilter.addDataScheme("package"); + getContext().registerReceiverAsUser(new PackageReceiver(), UserHandle.ALL, + packageFilter, null, null); + } + } + + @Override + public void onStart() { + } + + @Override + public void onBootPhase(int phase) { + if (phase == PHASE_BOOT_COMPLETED) { + mContentResolver = mContext.getContentResolver(); + mSettingsObserver = new SettingsObserver(); + if (mDriverPackageName == null || mDriverPackageName.isEmpty()) { + return; + } + fetchGameDriverPackageProperties(); + processBlacklists(); + setBlacklist(); + } + } + + private final class SettingsObserver extends ContentObserver { + private final Uri mGameDriverBlackUri = + Settings.Global.getUriFor(Settings.Global.GAME_DRIVER_BLACKLISTS); + + SettingsObserver() { + super(new Handler()); + mContentResolver.registerContentObserver(mGameDriverBlackUri, false, this, + UserHandle.USER_ALL); + } + + @Override + public void onChange(boolean selfChange, Uri uri) { + if (uri == null) { + return; + } + + if (mGameDriverBlackUri.equals(uri)) { + processBlacklists(); + setBlacklist(); + } + } + } + + private final class PackageReceiver extends BroadcastReceiver { + @Override + public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { + final Uri data = intent.getData(); + if (data == null && DEBUG) { + Slog.e(TAG, "Cannot handle package broadcast with null data"); + return; + } + final String packageName = data.getSchemeSpecificPart(); + if (!packageName.equals(mDriverPackageName)) { + return; + } + + final boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false); + + switch (intent.getAction()) { + case ACTION_PACKAGE_ADDED: + case ACTION_PACKAGE_CHANGED: + case ACTION_PACKAGE_REMOVED: + fetchGameDriverPackageProperties(); + setBlacklist(); + break; + default: + // do nothing + break; + } + } + } + + private static void assetToSettingsGlobal(Context context, Context driverContext, + String fileName, String settingsGlobal, CharSequence delimiter) { + try { + final BufferedReader reader = new BufferedReader( + new InputStreamReader(driverContext.getAssets().open(fileName))); + final ArrayList<String> assetStrings = new ArrayList<>(); + for (String assetString; (assetString = reader.readLine()) != null; ) { + assetStrings.add(assetString); + } + Settings.Global.putString(context.getContentResolver(), + settingsGlobal, + String.join(delimiter, assetStrings)); + } catch (IOException e) { + if (DEBUG) { + Slog.w(TAG, "Failed to load " + fileName + ", abort."); + } + } + } + + private void fetchGameDriverPackageProperties() { + final ApplicationInfo driverInfo; + try { + driverInfo = mPackageManager.getApplicationInfo(mDriverPackageName, + PackageManager.MATCH_SYSTEM_ONLY); + } catch (PackageManager.NameNotFoundException e) { + if (DEBUG) { + Slog.e(TAG, "driver package '" + mDriverPackageName + "' not installed"); + } + return; + } + + // O drivers are restricted to the sphal linker namespace, so don't try to use + // packages unless they declare they're compatible with that restriction. + if (driverInfo.targetSdkVersion < Build.VERSION_CODES.O) { + if (DEBUG) { + Slog.w(TAG, "Driver package is not known to be compatible with O"); + } + return; + } + + // Reset the whitelist. + Settings.Global.putString(mContentResolver, + Settings.Global.GAME_DRIVER_WHITELIST, ""); + // Reset the sphal libraries + Settings.Global.putString(mContentResolver, + Settings.Global.GAME_DRIVER_SPHAL_LIBRARIES, ""); + mGameDriverVersionCode = driverInfo.longVersionCode; + + try { + final Context driverContext = mContext.createPackageContext(mDriverPackageName, + Context.CONTEXT_RESTRICTED); + + assetToSettingsGlobal(mContext, driverContext, GAME_DRIVER_WHITELIST_FILENAME, + Settings.Global.GAME_DRIVER_WHITELIST, ","); + + assetToSettingsGlobal(mContext, driverContext, GAME_DRIVER_SPHAL_LIBRARIES_FILENAME, + Settings.Global.GAME_DRIVER_SPHAL_LIBRARIES, ":"); + + } catch (PackageManager.NameNotFoundException e) { + if (DEBUG) { + Slog.w(TAG, "driver package '" + mDriverPackageName + "' not installed"); + } + } + } + + private void processBlacklists() { + // TODO(b/121350991) Switch to DeviceConfig with property listener. + String base64String = + Settings.Global.getString(mContentResolver, Settings.Global.GAME_DRIVER_BLACKLISTS); + if (base64String == null || base64String.isEmpty()) { + return; + } + + synchronized (mLock) { + // Reset all blacklists + mBlacklists = null; + try { + mBlacklists = Blacklists.parseFrom(Base64.decode(base64String, BASE64_FLAGS)); + } catch (IllegalArgumentException e) { + if (DEBUG) { + Slog.w(TAG, "Can't parse blacklist, skip and continue..."); + } + } catch (InvalidProtocolBufferException e) { + if (DEBUG) { + Slog.w(TAG, "Can't parse blacklist, skip and continue..."); + } + } + } + } + + private void setBlacklist() { + Settings.Global.putString(mContentResolver, + Settings.Global.GAME_DRIVER_BLACKLIST, ""); + synchronized (mLock) { + if (mBlacklists == null) { + return; + } + List<Blacklist> blacklists = mBlacklists.getBlacklistsList(); + for (Blacklist blacklist : blacklists) { + if (blacklist.getVersionCode() == mGameDriverVersionCode) { + Settings.Global.putString(mContentResolver, + Settings.Global.GAME_DRIVER_BLACKLIST, + String.join(",", blacklist.getPackageNamesList())); + return; + } + } + } + } +} diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java index 7be7ab2bfb23..f0292aaded18 100644 --- a/services/java/com/android/server/SystemServer.java +++ b/services/java/com/android/server/SystemServer.java @@ -87,6 +87,7 @@ import com.android.server.display.DisplayManagerService; import com.android.server.dreams.DreamManagerService; import com.android.server.emergency.EmergencyAffordanceService; import com.android.server.fingerprint.FingerprintService; +import com.android.server.gpu.GpuService; import com.android.server.hdmi.HdmiControlService; import com.android.server.input.InputManagerService; import com.android.server.job.JobSchedulerService; @@ -747,6 +748,11 @@ public final class SystemServer { traceBeginAndSlog("StartBugreportManagerService"); mSystemServiceManager.startService(BugreportManagerService.class); traceEnd(); + + // Serivce for GPU and GPU driver. + traceBeginAndSlog("GpuService"); + mSystemServiceManager.startService(GpuService.class); + traceEnd(); } /** diff --git a/telephony/java/android/telephony/DataSpecificRegistrationInfo.java b/telephony/java/android/telephony/DataSpecificRegistrationInfo.java index 2cb369d28029..3dd931898c18 100644 --- a/telephony/java/android/telephony/DataSpecificRegistrationInfo.java +++ b/telephony/java/android/telephony/DataSpecificRegistrationInfo.java @@ -95,6 +95,21 @@ public final class DataSpecificRegistrationInfo implements Parcelable { this.mIsUsingCarrierAggregation = isUsingCarrierAggregation; } + /** + * Constructor from another data specific registration info + * + * @param dsri another data specific registration info + * @hide + */ + DataSpecificRegistrationInfo(DataSpecificRegistrationInfo dsri) { + maxDataCalls = dsri.maxDataCalls; + isDcNrRestricted = dsri.isDcNrRestricted; + isNrAvailable = dsri.isNrAvailable; + isEnDcAvailable = dsri.isEnDcAvailable; + mLteVopsSupportInfo = dsri.mLteVopsSupportInfo; + mIsUsingCarrierAggregation = dsri.mIsUsingCarrierAggregation; + } + private DataSpecificRegistrationInfo(Parcel source) { maxDataCalls = source.readInt(); isDcNrRestricted = source.readBoolean(); diff --git a/telephony/java/android/telephony/NetworkRegistrationInfo.java b/telephony/java/android/telephony/NetworkRegistrationInfo.java index 7b9f6d5eb8a1..2fae949cacb3 100644 --- a/telephony/java/android/telephony/NetworkRegistrationInfo.java +++ b/telephony/java/android/telephony/NetworkRegistrationInfo.java @@ -280,6 +280,39 @@ public final class NetworkRegistrationInfo implements Parcelable { } /** + * Constructor from another network registration info + * + * @param nri Another network registration info + * @hide + */ + public NetworkRegistrationInfo(NetworkRegistrationInfo nri) { + mDomain = nri.mDomain; + mTransportType = nri.mTransportType; + mRegistrationState = nri.mRegistrationState; + mRoamingType = nri.mRoamingType; + mAccessNetworkTechnology = nri.mAccessNetworkTechnology; + mRejectCause = nri.mRejectCause; + mEmergencyOnly = nri.mEmergencyOnly; + mAvailableServices = new ArrayList<>(nri.mAvailableServices); + if (nri.mCellIdentity != null) { + Parcel p = Parcel.obtain(); + nri.mCellIdentity.writeToParcel(p, 0); + p.setDataPosition(0); + // TODO: Instead of doing this, we should create a formal way for cloning cell identity. + // Cell identity is not an immutable object so we have to deep copy it. + mCellIdentity = CellIdentity.CREATOR.createFromParcel(p); + } + + if (nri.mVoiceSpecificInfo != null) { + mVoiceSpecificInfo = new VoiceSpecificRegistrationInfo(nri.mVoiceSpecificInfo); + } + if (nri.mDataSpecificInfo != null) { + mDataSpecificInfo = new DataSpecificRegistrationInfo(nri.mDataSpecificInfo); + } + mNrState = nri.mNrState; + } + + /** * @return The transport type. */ public @TransportType int getTransportType() { return mTransportType; } diff --git a/telephony/java/android/telephony/ServiceState.java b/telephony/java/android/telephony/ServiceState.java index f4a6984001cb..86cdce1ed3a6 100644 --- a/telephony/java/android/telephony/ServiceState.java +++ b/telephony/java/android/telephony/ServiceState.java @@ -418,7 +418,7 @@ public class ServiceState implements Parcelable { Arrays.copyOf(s.mCellBandwidths, s.mCellBandwidths.length); mLteEarfcnRsrpBoost = s.mLteEarfcnRsrpBoost; mNetworkRegistrationInfos = s.mNetworkRegistrationInfos == null ? null : - new ArrayList<>(s.mNetworkRegistrationInfos); + s.getNetworkRegistrationInfoList(); mNrFrequencyRange = s.mNrFrequencyRange; } @@ -1113,16 +1113,16 @@ public class ServiceState implements Parcelable { /** @hide */ @TestApi public void setVoiceRoamingType(@RoamingType int type) { - NetworkRegistrationInfo regState = getNetworkRegistrationInfo( + NetworkRegistrationInfo regInfo = getNetworkRegistrationInfo( NetworkRegistrationInfo.DOMAIN_CS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN); - if (regState == null) { - regState = new NetworkRegistrationInfo.Builder() + if (regInfo == null) { + regInfo = new NetworkRegistrationInfo.Builder() .setDomain(NetworkRegistrationInfo.DOMAIN_CS) .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN) .build(); - addNetworkRegistrationInfo(regState); } - regState.setRoamingType(type); + regInfo.setRoamingType(type); + addNetworkRegistrationInfo(regInfo); } /** @hide */ @@ -1134,16 +1134,16 @@ public class ServiceState implements Parcelable { /** @hide */ @TestApi public void setDataRoamingType(@RoamingType int type) { - NetworkRegistrationInfo regState = getNetworkRegistrationInfo( + NetworkRegistrationInfo regInfo = getNetworkRegistrationInfo( NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN); - if (regState == null) { - regState = new NetworkRegistrationInfo.Builder() + if (regInfo == null) { + regInfo = new NetworkRegistrationInfo.Builder() .setDomain(NetworkRegistrationInfo.DOMAIN_PS) .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN) .build(); - addNetworkRegistrationInfo(regState); } - regState.setRoamingType(type); + regInfo.setRoamingType(type); + addNetworkRegistrationInfo(regInfo); } /** @@ -1305,16 +1305,16 @@ public class ServiceState implements Parcelable { Rlog.e(LOG_TAG, "ServiceState.setRilVoiceRadioTechnology() called. It's encouraged to " + "use addNetworkRegistrationInfo() instead *******"); // Sync to network registration state - NetworkRegistrationInfo regState = getNetworkRegistrationInfo( + NetworkRegistrationInfo regInfo = getNetworkRegistrationInfo( NetworkRegistrationInfo.DOMAIN_CS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN); - if (regState == null) { - regState = new NetworkRegistrationInfo.Builder() + if (regInfo == null) { + regInfo = new NetworkRegistrationInfo.Builder() .setDomain(NetworkRegistrationInfo.DOMAIN_CS) .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN) .build(); - addNetworkRegistrationInfo(regState); } - regState.setAccessNetworkTechnology(rilRadioTechnologyToNetworkType(rt)); + regInfo.setAccessNetworkTechnology(rilRadioTechnologyToNetworkType(rt)); + addNetworkRegistrationInfo(regInfo); } @@ -1326,17 +1326,17 @@ public class ServiceState implements Parcelable { // Sync to network registration state. Always write down the WWAN transport. For AP-assisted // mode device, use addNetworkRegistrationInfo() to set the correct transport if RAT // is IWLAN. - NetworkRegistrationInfo regState = getNetworkRegistrationInfo( + NetworkRegistrationInfo regInfo = getNetworkRegistrationInfo( NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN); - if (regState == null) { - regState = new NetworkRegistrationInfo.Builder() + if (regInfo == null) { + regInfo = new NetworkRegistrationInfo.Builder() .setDomain(NetworkRegistrationInfo.DOMAIN_PS) .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN) .build(); - addNetworkRegistrationInfo(regState); } - regState.setAccessNetworkTechnology(rilRadioTechnologyToNetworkType(rt)); + regInfo.setAccessNetworkTechnology(rilRadioTechnologyToNetworkType(rt)); + addNetworkRegistrationInfo(regInfo); } /** @hide */ @@ -1378,10 +1378,10 @@ public class ServiceState implements Parcelable { * @hide */ public @NRState int getNrState() { - final NetworkRegistrationInfo regState = getNetworkRegistrationInfo( + final NetworkRegistrationInfo regInfo = getNetworkRegistrationInfo( NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN); - if (regState == null) return NetworkRegistrationInfo.NR_STATE_NONE; - return regState.getNrState(); + if (regInfo == null) return NetworkRegistrationInfo.NR_STATE_NONE; + return regInfo.getNrState(); } /** @@ -1775,7 +1775,11 @@ public class ServiceState implements Parcelable { @SystemApi public List<NetworkRegistrationInfo> getNetworkRegistrationInfoList() { synchronized (mNetworkRegistrationInfos) { - return new ArrayList<>(mNetworkRegistrationInfos); + List<NetworkRegistrationInfo> newList = new ArrayList<>(); + for (NetworkRegistrationInfo nri : mNetworkRegistrationInfos) { + newList.add(new NetworkRegistrationInfo(nri)); + } + return newList; } } @@ -1795,7 +1799,7 @@ public class ServiceState implements Parcelable { synchronized (mNetworkRegistrationInfos) { for (NetworkRegistrationInfo networkRegistrationInfo : mNetworkRegistrationInfos) { if (networkRegistrationInfo.getTransportType() == transportType) { - list.add(networkRegistrationInfo); + list.add(new NetworkRegistrationInfo(networkRegistrationInfo)); } } } @@ -1819,7 +1823,7 @@ public class ServiceState implements Parcelable { synchronized (mNetworkRegistrationInfos) { for (NetworkRegistrationInfo networkRegistrationInfo : mNetworkRegistrationInfos) { if (networkRegistrationInfo.getDomain() == domain) { - list.add(networkRegistrationInfo); + list.add(new NetworkRegistrationInfo(networkRegistrationInfo)); } } } @@ -1844,7 +1848,7 @@ public class ServiceState implements Parcelable { for (NetworkRegistrationInfo networkRegistrationInfo : mNetworkRegistrationInfos) { if (networkRegistrationInfo.getTransportType() == transportType && networkRegistrationInfo.getDomain() == domain) { - return networkRegistrationInfo; + return new NetworkRegistrationInfo(networkRegistrationInfo); } } } @@ -1856,20 +1860,20 @@ public class ServiceState implements Parcelable { * @hide */ @TestApi - public void addNetworkRegistrationInfo(NetworkRegistrationInfo regState) { - if (regState == null) return; + public void addNetworkRegistrationInfo(NetworkRegistrationInfo nri) { + if (nri == null) return; synchronized (mNetworkRegistrationInfos) { for (int i = 0; i < mNetworkRegistrationInfos.size(); i++) { NetworkRegistrationInfo curRegState = mNetworkRegistrationInfos.get(i); - if (curRegState.getTransportType() == regState.getTransportType() - && curRegState.getDomain() == regState.getDomain()) { + if (curRegState.getTransportType() == nri.getTransportType() + && curRegState.getDomain() == nri.getDomain()) { mNetworkRegistrationInfos.remove(i); break; } } - mNetworkRegistrationInfos.add(regState); + mNetworkRegistrationInfos.add(new NetworkRegistrationInfo(nri)); } } diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java index 586c815ae7b5..58c05aa3ccba 100644 --- a/telephony/java/android/telephony/SubscriptionManager.java +++ b/telephony/java/android/telephony/SubscriptionManager.java @@ -294,6 +294,19 @@ public class SubscriptionManager { public static final String SUBSCRIPTION_TYPE = "subscription_type"; /** + * TelephonyProvider column name white_listed_apn_data. + * It's a bitmask of APN types that will be allowed on this subscription even if it's metered + * and mobile data is turned off by the user. + * <P>Type: INTEGER (int)</P> For example, if TYPE_MMS is is true, Telephony will allow MMS + * data connection to setup even if MMS is metered and mobile_data is turned off on that + * subscription. + * + * Default value is 0. + */ + /** @hide */ + public static final String WHITE_LISTED_APN_DATA = "white_listed_apn_data"; + + /** * This constant is to designate a subscription as a Local-SIM Subscription. * <p> A Local-SIM can be a physical SIM inserted into a sim-slot in the device, or eSIM on the * device. @@ -3087,6 +3100,31 @@ public class SubscriptionManager { return subId; } + /** + * Set whether a subscription always allows MMS connection. If true, MMS network + * request will be accepted by telephony even if user turns "mobile data" off + * on this subscription. + * + * @param subId which subscription it's setting to. + * @param alwaysAllow whether Mms data is always allowed. + * @return whether operation is successful. + * + * @hide + */ + public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) { + try { + ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub")); + if (iSub != null) { + return iSub.setAlwaysAllowMmsData(subId, alwaysAllow); + } + } catch (RemoteException ex) { + if (!isSystemProcess()) { + ex.rethrowAsRuntimeException(); + } + } + return false; + } + private interface CallISubMethodHelper { int callMethod(ISub iSub) throws RemoteException; } diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index e1425b975525..82cc1df08f4f 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -64,6 +64,7 @@ import android.telecom.PhoneAccount; import android.telecom.PhoneAccountHandle; import android.telecom.TelecomManager; import android.telephony.VisualVoicemailService.VisualVoicemailTask; +import android.telephony.data.ApnSetting; import android.telephony.emergency.EmergencyNumber; import android.telephony.emergency.EmergencyNumber.EmergencyServiceCategories; import android.telephony.ims.aidl.IImsConfig; @@ -10888,4 +10889,58 @@ public class TelephonyManager { } return new Pair<Integer, Integer>(-1, -1); } + + /** + * Return whether data is enabled for certain APN type. This will tell if framework will accept + * corresponding network requests on a subId. + * + * {@link #isDataEnabled()} is directly associated with users' Mobile data toggle on / off. If + * {@link #isDataEnabled()} returns false, it means in general all meter-ed data are disabled. + * + * This per APN type API gives a better idea whether data is allowed on a specific APN type. + * It will return true if: + * + * 1) User data is turned on, or + * 2) APN is un-metered for this subscription, or + * 3) APN type is whitelisted. E.g. MMS is whitelisted if + * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on. + * + * @return whether data is enabled for a apn type. + * + * @hide + */ + public boolean isDataEnabledForApn(@ApnSetting.ApnType int apnType) { + String pkgForDebug = mContext != null ? mContext.getOpPackageName() : "<unknown>"; + try { + ITelephony service = getITelephony(); + if (service != null) { + return service.isDataEnabledForApn(apnType, getSubId(), pkgForDebug); + } + } catch (RemoteException ex) { + if (!isSystemProcess()) { + ex.rethrowAsRuntimeException(); + } + } + return false; + } + + /** + * Whether an APN type is metered or not. It will be evaluated with the subId associated + * with the TelephonyManager instance. + * + * @hide + */ + public boolean isApnMetered(@ApnSetting.ApnType int apnType) { + try { + ITelephony service = getITelephony(); + if (service != null) { + return service.isApnMetered(apnType, getSubId()); + } + } catch (RemoteException ex) { + if (!isSystemProcess()) { + ex.rethrowAsRuntimeException(); + } + } + return true; + } } diff --git a/telephony/java/android/telephony/VoiceSpecificRegistrationInfo.java b/telephony/java/android/telephony/VoiceSpecificRegistrationInfo.java index 18a533a46273..d43181e68c28 100644 --- a/telephony/java/android/telephony/VoiceSpecificRegistrationInfo.java +++ b/telephony/java/android/telephony/VoiceSpecificRegistrationInfo.java @@ -65,6 +65,19 @@ public class VoiceSpecificRegistrationInfo implements Parcelable{ this.defaultRoamingIndicator = defaultRoamingIndicator; } + /** + * Constructor from another voice specific registration info + * + * @param vsri another voice specific registration info + * @hide + */ + VoiceSpecificRegistrationInfo(VoiceSpecificRegistrationInfo vsri) { + cssSupported = vsri.cssSupported; + roamingIndicator = vsri.roamingIndicator; + systemIsInPrl = vsri.systemIsInPrl; + defaultRoamingIndicator = vsri.defaultRoamingIndicator; + } + private VoiceSpecificRegistrationInfo(Parcel source) { this.cssSupported = source.readBoolean(); this.roamingIndicator = source.readInt(); diff --git a/telephony/java/com/android/internal/telephony/DctConstants.java b/telephony/java/com/android/internal/telephony/DctConstants.java index 6e8d038eda4f..bb5c251b69e1 100644 --- a/telephony/java/com/android/internal/telephony/DctConstants.java +++ b/telephony/java/com/android/internal/telephony/DctConstants.java @@ -94,6 +94,7 @@ public class DctConstants { public static final int EVENT_ROAMING_SETTING_CHANGE = BASE + 48; public static final int EVENT_DATA_SERVICE_BINDING_CHANGED = BASE + 49; public static final int EVENT_DEVICE_PROVISIONED_CHANGE = BASE + 50; + public static final int EVENT_APN_WHITE_LIST_CHANGE = BASE + 51; /***** Constants *****/ diff --git a/telephony/java/com/android/internal/telephony/ISub.aidl b/telephony/java/com/android/internal/telephony/ISub.aidl index 118f5e26e6e7..f248893ec638 100755 --- a/telephony/java/com/android/internal/telephony/ISub.aidl +++ b/telephony/java/com/android/internal/telephony/ISub.aidl @@ -283,4 +283,6 @@ interface ISub { int getSimStateForSlotIndex(int slotIndex); boolean isActiveSubId(int subId, String callingPackage); + + boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow); } diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl index d173cc9c44e5..0ad60963c398 100644 --- a/telephony/java/com/android/internal/telephony/ITelephony.aidl +++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl @@ -1958,4 +1958,8 @@ interface ITelephony { int getRadioHalVersion(); boolean isModemEnabledForSlot(int slotIndex, String callingPackage); + + boolean isDataEnabledForApn(int apnType, int subId, String callingPackage); + + boolean isApnMetered(int apnType, int subId); } diff --git a/tools/aapt2/ResourceUtils.cpp b/tools/aapt2/ResourceUtils.cpp index 99420de47fca..609e3660375e 100644 --- a/tools/aapt2/ResourceUtils.cpp +++ b/tools/aapt2/ResourceUtils.cpp @@ -497,9 +497,9 @@ Maybe<int> ParseSdkVersion(const StringPiece& str) { } // Try parsing the code name. - std::pair<StringPiece, int> entry = GetDevelopmentSdkCodeNameAndVersion(); - if (entry.first == trimmed_str) { - return entry.second; + Maybe<int> entry = GetDevelopmentSdkCodeNameVersion(trimmed_str); + if (entry) { + return entry.value(); } return {}; } diff --git a/tools/aapt2/SdkConstants.cpp b/tools/aapt2/SdkConstants.cpp index 8ebde752bc4b..b4b6ff1daaaa 100644 --- a/tools/aapt2/SdkConstants.cpp +++ b/tools/aapt2/SdkConstants.cpp @@ -18,15 +18,17 @@ #include <algorithm> #include <string> -#include <unordered_map> +#include <unordered_set> #include <vector> using android::StringPiece; namespace aapt { -static const char* sDevelopmentSdkCodeName = "P"; -static ApiVersion sDevelopmentSdkLevel = 28; +static ApiVersion sDevelopmentSdkLevel = 10000; +static const auto sDevelopmentSdkCodeNames = std::unordered_set<StringPiece>({ + "Q", "R" +}); static const std::vector<std::pair<uint16_t, ApiVersion>> sAttrIdMap = { {0x021c, 1}, @@ -54,6 +56,7 @@ static const std::vector<std::pair<uint16_t, ApiVersion>> sAttrIdMap = { {0x0530, SDK_NOUGAT_MR1}, {0x0568, SDK_O}, {0x056d, SDK_O_MR1}, + {0x0586, SDK_P}, }; static bool less_entry_id(const std::pair<uint16_t, ApiVersion>& p, uint16_t entryId) { @@ -71,8 +74,9 @@ ApiVersion FindAttributeSdkLevel(const ResourceId& id) { return iter->second; } -std::pair<StringPiece, ApiVersion> GetDevelopmentSdkCodeNameAndVersion() { - return std::make_pair(StringPiece(sDevelopmentSdkCodeName), sDevelopmentSdkLevel); +Maybe<ApiVersion> GetDevelopmentSdkCodeNameVersion(const StringPiece& code_name) { + return (sDevelopmentSdkCodeNames.find(code_name) == sDevelopmentSdkCodeNames.end()) + ? Maybe<ApiVersion>() : sDevelopmentSdkLevel; } } // namespace aapt diff --git a/tools/aapt2/SdkConstants.h b/tools/aapt2/SdkConstants.h index 9fa29f25c29c..adb034a95328 100644 --- a/tools/aapt2/SdkConstants.h +++ b/tools/aapt2/SdkConstants.h @@ -57,7 +57,7 @@ enum : ApiVersion { }; ApiVersion FindAttributeSdkLevel(const ResourceId& id); -std::pair<android::StringPiece, ApiVersion> GetDevelopmentSdkCodeNameAndVersion(); +Maybe<ApiVersion> GetDevelopmentSdkCodeNameVersion(const android::StringPiece& code_name); } // namespace aapt diff --git a/tools/aapt2/configuration/ConfigurationParser_test.cpp b/tools/aapt2/configuration/ConfigurationParser_test.cpp index 4c23bd3d6e3e..2ef8b999a192 100644 --- a/tools/aapt2/configuration/ConfigurationParser_test.cpp +++ b/tools/aapt2/configuration/ConfigurationParser_test.cpp @@ -705,35 +705,24 @@ TEST_F(ConfigurationParserTest, AndroidSdkGroupAction_InvalidVersion) { } TEST_F(ConfigurationParserTest, AndroidSdkGroupAction_NonNumeric) { - static constexpr const char* xml = R"xml( + auto doc = test::BuildXmlDom(R"xml( <android-sdk - label="P" + label="Q" minSdkVersion="25" - targetSdkVersion="%s" - maxSdkVersion="%s"> - </android-sdk>)xml"; - - const auto& dev_sdk = GetDevelopmentSdkCodeNameAndVersion(); - const char* codename = dev_sdk.first.data(); - const ApiVersion& version = dev_sdk.second; - - auto doc = test::BuildXmlDom(StringPrintf(xml, codename, codename)); + targetSdkVersion="Q" + maxSdkVersion="Q"> + </android-sdk>)xml"); PostProcessingConfiguration config; - bool ok = AndroidSdkTagHandler(&config, NodeCast<Element>(doc.get()->root.get()), &diag_); - ASSERT_TRUE(ok); - + ASSERT_TRUE(AndroidSdkTagHandler(&config, NodeCast<Element>(doc.get()->root.get()), &diag_)); ASSERT_EQ(1ul, config.android_sdks.size()); - ASSERT_EQ(1u, config.android_sdks.count("P")); - - auto& out = config.android_sdks["P"]; + ASSERT_EQ(1u, config.android_sdks.count("Q")); AndroidSdk sdk; sdk.min_sdk_version = 25; - sdk.target_sdk_version = version; - sdk.max_sdk_version = version; - - ASSERT_EQ(sdk, out); + sdk.target_sdk_version = 10000; + sdk.max_sdk_version = 10000; + ASSERT_EQ(sdk, config.android_sdks["Q"]); } TEST_F(ConfigurationParserTest, GlTextureGroupAction) { |