Create returns null when resource strings are empty

When resource string for the shared connectivity service or intent
are empty, the create method now returns null instead of creating
the manager.

Bug: 277383431
Test: atest SharedConnectivityManagerTest
Change-Id: Ib192821ed2311fb80689cef3c9adc31bf2c21f5b
This commit is contained in:
Isaac Katzenelson
2023-04-07 22:46:40 +00:00
parent fd64019fcb
commit 6547db707a
2 changed files with 14 additions and 1 deletions

View File

@@ -35,6 +35,7 @@ import android.os.Binder;
import android.os.IBinder;
import android.os.IInterface;
import android.os.RemoteException;
import android.text.TextUtils;
import android.util.Log;
import com.android.internal.R;
@@ -173,10 +174,15 @@ public class SharedConnectivityManager {
R.string.config_sharedConnectivityServicePackage);
String serviceIntentAction = resources.getString(
R.string.config_sharedConnectivityServiceIntentAction);
if (TextUtils.isEmpty(servicePackageName) || TextUtils.isEmpty(serviceIntentAction)) {
Log.e(TAG, "To support shared connectivity service on this device, the"
+ " service's package name and intent action strings must not be empty");
return null;
}
return new SharedConnectivityManager(context, servicePackageName, serviceIntentAction);
} catch (Resources.NotFoundException e) {
Log.e(TAG, "To support shared connectivity service on this device, the service's"
+ " package name and intent action string must be defined");
+ " package name and intent action strings must be defined");
}
return null;
}

View File

@@ -104,6 +104,13 @@ public class SharedConnectivityManagerTest {
assertThat(SharedConnectivityManager.create(mContext)).isNull();
}
@Test
public void resourceStringsAreEmpty_createShouldReturnNull() {
when(mResources.getString(anyInt())).thenReturn("");
assertThat(SharedConnectivityManager.create(mContext)).isNull();
}
@Test
public void bindingToServiceOnFirstCallbackRegistration() {
SharedConnectivityManager manager = SharedConnectivityManager.create(mContext);