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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user