summaryrefslogtreecommitdiff
path: root/wifi/java
diff options
context:
space:
mode:
author Isaac Katzenelson <isaackatz@google.com> 2023-02-11 01:44:27 +0000
committer Isaac Katzenelson <isaack@android.com> 2023-02-13 22:07:38 +0000
commitca8e637bac317faac7cff384815812ee054f6c42 (patch)
tree83dee0487eb9060058e4e60c20262f103164a4dd /wifi/java
parentefa29460727a4c1ceee415471703ffb3173a143f (diff)
Read service package and intent action from resources
Bug: 268741563 Test: atest SharedConnectivityManagerTest Change-Id: Iab3843749faaf8eb5399bc6395e75a6cc611252f
Diffstat (limited to 'wifi/java')
-rw-r--r--wifi/java/src/android/net/wifi/sharedconnectivity/app/SharedConnectivityManager.java57
1 files changed, 30 insertions, 27 deletions
diff --git a/wifi/java/src/android/net/wifi/sharedconnectivity/app/SharedConnectivityManager.java b/wifi/java/src/android/net/wifi/sharedconnectivity/app/SharedConnectivityManager.java
index c2981899d2ab..8aa369e31ce8 100644
--- a/wifi/java/src/android/net/wifi/sharedconnectivity/app/SharedConnectivityManager.java
+++ b/wifi/java/src/android/net/wifi/sharedconnectivity/app/SharedConnectivityManager.java
@@ -35,6 +35,8 @@ import android.os.IInterface;
import android.os.RemoteException;
import android.util.Log;
+import com.android.internal.R;
+
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -51,8 +53,6 @@ import java.util.concurrent.Executor;
public class SharedConnectivityManager {
private static final String TAG = SharedConnectivityManager.class.getSimpleName();
private static final boolean DEBUG = true;
- private static final String SERVICE_PACKAGE_NAME = "sharedconnectivity_service_package";
- private static final String SERVICE_CLASS_NAME = "sharedconnectivity_service_class";
private static final class SharedConnectivityCallbackProxy extends
ISharedConnectivityCallback.Stub {
@@ -101,7 +101,7 @@ public class SharedConnectivityManager {
Binder.restoreCallingIdentity(token);
}
}
- };
+ }
@Override
public void onTetherNetworkConnectionStatusChanged(
@@ -115,7 +115,7 @@ public class SharedConnectivityManager {
Binder.restoreCallingIdentity(token);
}
}
- };
+ }
@Override
public void onKnownNetworkConnectionStatusChanged(
@@ -129,7 +129,7 @@ public class SharedConnectivityManager {
Binder.restoreCallingIdentity(token);
}
}
- };
+ }
}
private ISharedConnectivityService mService;
@@ -137,14 +137,33 @@ public class SharedConnectivityManager {
mProxyMap = new HashMap<>();
/**
- * Constructor for new instance of {@link SharedConnectivityManager}.
+ * Creates a new instance of {@link SharedConnectivityManager}.
*
* Automatically binds to implementation of {@link SharedConnectivityService} specified in
* device overlay.
*
+ * @return An instance of {@link SharedConnectivityManager} or null if the shared connectivity
+ * service is not found.
* @hide
*/
- public SharedConnectivityManager(@NonNull Context context) {
+ @Nullable
+ public static SharedConnectivityManager create(@NonNull Context context) {
+ Resources resources = context.getResources();
+ try {
+ String servicePackageName = resources.getString(
+ R.string.shared_connectivity_service_package);
+ String serviceIntentAction = resources.getString(
+ R.string.shared_connectivity_service_intent_action);
+ 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");
+ }
+ return null;
+ }
+
+ private SharedConnectivityManager(@NonNull Context context, String servicePackageName,
+ String serviceIntentAction) {
ServiceConnection serviceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
@@ -158,7 +177,10 @@ public class SharedConnectivityManager {
mProxyMap.clear();
}
};
- bind(context, serviceConnection);
+
+ context.bindService(
+ new Intent().setPackage(servicePackageName).setAction(serviceIntentAction),
+ serviceConnection, Context.BIND_AUTO_CREATE);
}
/**
@@ -169,25 +191,6 @@ public class SharedConnectivityManager {
mService = (ISharedConnectivityService) service;
}
- private void bind(Context context, ServiceConnection serviceConnection) {
- Resources resources = context.getResources();
- int packageNameId = resources.getIdentifier(SERVICE_PACKAGE_NAME, "string",
- context.getPackageName());
- int classNameId = resources.getIdentifier(SERVICE_CLASS_NAME, "string",
- context.getPackageName());
- if (packageNameId == 0 || classNameId == 0) {
- throw new Resources.NotFoundException("Package and class names for"
- + " shared connectivity service must be defined");
- }
-
- Intent intent = new Intent();
- intent.setComponent(new ComponentName(resources.getString(packageNameId),
- resources.getString(classNameId)));
- context.bindService(
- intent,
- serviceConnection, Context.BIND_AUTO_CREATE);
- }
-
/**
* Registers a callback for receiving updates to the list of Tether Networks and Known Networks.
*