Merge "Create returns null when resource strings are empty" into udc-dev

This commit is contained in:
Isaac Katzenelson
2023-04-09 22:09:04 +00:00
committed by Android (Google) Code Review
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);