diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2021-03-05 23:05:48 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2021-03-05 23:05:48 +0000 |
commit | 5ea5ac08c21d9dc59cd768b99931a2b630bbf05f (patch) | |
tree | 899f7eb5dc1113baa30e5709841c73a797706a49 | |
parent | 494d86c8d13965315e2df78b2743fceb4e66d30f (diff) | |
parent | 2e6f670e6fd6ffa6065280e057b4a68dbc68a44e (diff) | |
download | CertInstaller-5ea5ac08c21d9dc59cd768b99931a2b630bbf05f.tar.gz |
Snap for 7187929 from 2e6f670e6fd6ffa6065280e057b4a68dbc68a44e to rvc-qpr3-release
Change-Id: Ie6b30901c0856184027a0ebdfcd275ba409ae979
-rw-r--r-- | src/com/android/certinstaller/WiFiInstaller.java | 69 |
1 files changed, 47 insertions, 22 deletions
diff --git a/src/com/android/certinstaller/WiFiInstaller.java b/src/com/android/certinstaller/WiFiInstaller.java index 41827f6..7ddee49 100644 --- a/src/com/android/certinstaller/WiFiInstaller.java +++ b/src/com/android/certinstaller/WiFiInstaller.java @@ -13,6 +13,8 @@ import android.net.wifi.hotspot2.PasspointConfiguration; import android.os.AsyncTask; import android.os.Bundle; import android.provider.DocumentsContract; +import android.text.TextUtils; +import android.util.EventLog; import android.util.Log; import android.view.View; import android.widget.TextView; @@ -26,18 +28,23 @@ public class WiFiInstaller extends Activity { private static final String TAG = "WifiInstaller"; private static final String NETWORK_NAME = "network_name"; private static final String INSTALL_STATE = "install_state"; + private static final String TYPE_WIFI_CONFIG = "application/x-wifi-config"; public static final int INSTALL_SUCCESS = 2; public static final int INSTALL_FAIL = 1; public static final int INSTALL_FAIL_NO_WIFI = 0; - PasspointConfiguration mPasspointConfig; - WifiManager mWifiManager; - boolean doNotInstall; + private PasspointConfiguration mPasspointConfig; + private boolean mIsPasspointConfigurationValid; @Override protected void onCreate(Bundle savedStates) { super.onCreate(savedStates); + mIsPasspointConfigurationValid = false; Bundle bundle = getIntent().getExtras(); + if (bundle == null) { + Log.e(TAG, "Invalid inputs"); + return; + } String uriString = bundle.getString(CertInstallerMain.WIFI_CONFIG_FILE); String mimeType = bundle.getString(CertInstallerMain.WIFI_CONFIG); byte[] data = bundle.getByteArray(CertInstallerMain.WIFI_CONFIG_DATA); @@ -45,17 +52,34 @@ public class WiFiInstaller extends Activity { Log.d(TAG, "WiFi data for " + CertInstallerMain.WIFI_CONFIG + ": " + mimeType + " is " + (data != null ? data.length : "-")); - mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); - mPasspointConfig = ConfigParser.parsePasspointConfig(mimeType, data); - dropFile(Uri.parse(uriString), getApplicationContext()); + // Make sure that the input is valid + if (data == null || data.length == 0 || TextUtils.isEmpty(uriString)) { + Log.e(TAG, "Invalid inputs"); + return; + } + + // Verify MIME type before parsing + if (!TextUtils.equals(mimeType, TYPE_WIFI_CONFIG)) { + Log.e(TAG, "Unexpected MIME type: " + mimeType); + EventLog.writeEvent(0x534e4554, "176756691", -1, "Invalid mime-type"); + return; + } + mPasspointConfig = ConfigParser.parsePasspointConfig(mimeType, data); if (mPasspointConfig == null) { - Log.w(TAG, "failed to build passpoint configuration"); - doNotInstall = true; - } else if (mPasspointConfig.getHomeSp() == null) { - Log.w(TAG, "Passpoint profile missing HomeSP information"); - doNotInstall = true; + Log.e(TAG, "Failed to build Passpoint configuration"); + EventLog.writeEvent(0x534e4554, "176756691", -1, "Invalid data in file " + + uriString); + return; + } + if (mPasspointConfig.getHomeSp() == null) { + Log.e(TAG, "Passpoint profile missing HomeSP information"); + } else { + // Passpoint configuration parsed successfully and valid. Mark to be installed. + mIsPasspointConfigurationValid = true; } + // Delete the file only if the Passpoint configuration was parsed successfully + dropFile(Uri.parse(uriString), getApplicationContext()); } @Override @@ -75,7 +99,8 @@ public class WiFiInstaller extends Activity { builder.setView(layout); TextView text = (TextView) layout.findViewById(R.id.wifi_info); - if (!doNotInstall) { + if (mIsPasspointConfigurationValid) { + WifiManager wifiManager = getSystemService(WifiManager.class); text.setText(String.format(getResources().getString(R.string.wifi_installer_detail), mPasspointConfig.getHomeSp().getFriendlyName())); @@ -93,14 +118,14 @@ public class WiFiInstaller extends Activity { public void run() { boolean success = true; try { - mWifiManager.removePasspointConfiguration( + wifiManager.removePasspointConfiguration( mPasspointConfig.getHomeSp().getFqdn()); } catch (IllegalArgumentException e) { // Do nothing. This is expected if a profile with this FQDN does not // exist. } try { - mWifiManager.addOrUpdatePasspointConfiguration(mPasspointConfig); + wifiManager.addOrUpdatePasspointConfiguration(mPasspointConfig); } catch (RuntimeException rte) { Log.w(TAG, "Caught exception while installing wifi config: " + rte, rte); @@ -154,14 +179,14 @@ public class WiFiInstaller extends Activity { * @param context The context of the current application */ private static void dropFile(Uri uri, Context context) { - try { - if (DocumentsContract.isDocumentUri(context, uri)) { - DocumentsContract.deleteDocument(context.getContentResolver(), uri); - } else { - context.getContentResolver().delete(uri, null, null); + try { + if (DocumentsContract.isDocumentUri(context, uri)) { + DocumentsContract.deleteDocument(context.getContentResolver(), uri); + } else { + context.getContentResolver().delete(uri, null, null); + } + } catch (Exception e) { + Log.e(TAG, "could not delete document " + uri); } - } catch (Exception e) { - Log.e(TAG, "could not delete document " + uri); - } } } |