Merge "Protect invalid entitlement app configuration" into rvc-dev am: 06b2e1cb17
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11699076 Change-Id: I1d9075a7c112dd1345d6a8dacf343886dc1b286b
This commit is contained in:
@@ -18,6 +18,7 @@ package com.android.networkstack.tethering;
|
||||
|
||||
import static android.Manifest.permission.NETWORK_SETTINGS;
|
||||
import static android.Manifest.permission.NETWORK_STACK;
|
||||
import static android.content.pm.PackageManager.GET_ACTIVITIES;
|
||||
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
||||
import static android.hardware.usb.UsbManager.USB_CONFIGURED;
|
||||
import static android.hardware.usb.UsbManager.USB_CONNECTED;
|
||||
@@ -70,6 +71,7 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.hardware.usb.UsbManager;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.EthernetManager;
|
||||
@@ -109,7 +111,6 @@ import android.os.RemoteCallbackList;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ResultReceiver;
|
||||
import android.os.ServiceSpecificException;
|
||||
import android.os.SystemProperties;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
@@ -782,11 +783,30 @@ public class Tethering {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isProvisioningNeededButUnavailable() {
|
||||
return isTetherProvisioningRequired() && !doesEntitlementPackageExist();
|
||||
}
|
||||
|
||||
boolean isTetherProvisioningRequired() {
|
||||
final TetheringConfiguration cfg = mConfig;
|
||||
return mEntitlementMgr.isTetherProvisioningRequired(cfg);
|
||||
}
|
||||
|
||||
private boolean doesEntitlementPackageExist() {
|
||||
// provisioningApp must contain package and class name.
|
||||
if (mConfig.provisioningApp.length != 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final PackageManager pm = mContext.getPackageManager();
|
||||
try {
|
||||
pm.getPackageInfo(mConfig.provisioningApp[0], GET_ACTIVITIES);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO: Figure out how to update for local hotspot mode interfaces.
|
||||
private void sendTetherStateChangedBroadcast() {
|
||||
if (!isTetheringSupported()) return;
|
||||
@@ -2146,14 +2166,14 @@ public class Tethering {
|
||||
// gservices could set the secure setting to 1 though to enable it on a build where it
|
||||
// had previously been turned off.
|
||||
boolean isTetheringSupported() {
|
||||
final int defaultVal =
|
||||
SystemProperties.get("ro.tether.denied").equals("true") ? 0 : 1;
|
||||
final int defaultVal = mDeps.isTetheringDenied() ? 0 : 1;
|
||||
final boolean tetherSupported = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.TETHER_SUPPORTED, defaultVal) != 0;
|
||||
final boolean tetherEnabledInSettings = tetherSupported
|
||||
&& !mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING);
|
||||
|
||||
return tetherEnabledInSettings && hasTetherableConfiguration();
|
||||
return tetherEnabledInSettings && hasTetherableConfiguration()
|
||||
&& !isProvisioningNeededButUnavailable();
|
||||
}
|
||||
|
||||
void dump(@NonNull FileDescriptor fd, @NonNull PrintWriter writer, @Nullable String[] args) {
|
||||
|
||||
@@ -26,6 +26,8 @@ import android.net.util.SharedLog;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.Looper;
|
||||
import android.os.SystemProperties;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
@@ -150,4 +152,11 @@ public abstract class TetheringDependencies {
|
||||
* Get a reference to BluetoothAdapter to be used by tethering.
|
||||
*/
|
||||
public abstract BluetoothAdapter getBluetoothAdapter();
|
||||
|
||||
/**
|
||||
* Get SystemProperties which indicate whether tethering is denied.
|
||||
*/
|
||||
public boolean isTetheringDenied() {
|
||||
return TextUtils.equals(SystemProperties.get("ro.tether.denied"), "true");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user