Add init intent support (API v2)

For proper dynamic permission support
This commit is contained in:
Marvin W 2016-02-22 23:10:22 +01:00
parent b26d5137ee
commit bd671aeeff
7 changed files with 67 additions and 6 deletions

@ -1 +1 @@
Subproject commit 18fb8cb8a189d675f8bfbddcfac3f4396c2aba0a
Subproject commit c6a81f4d7d978418352648cecd2545ea575a8caf

@ -1 +1 @@
Subproject commit a818694d1d27601d9f00d0fbf36f8eff7f6a15fd
Subproject commit af1743ca443aa005805b5ab2d9f66eb6e7d886e6

View file

@ -38,7 +38,7 @@ public class PackageReceiver extends BroadcastReceiver {
}
if (preferences.getGeocoderBackends().contains(packageName)) {
Log.d(TAG, "Reloading geocoding service for " + packageName);
AbstractGeocodeService.reloadLocationService(context);
AbstractGeocodeService.reloadGeocodeService(context);
}
}
}

View file

@ -24,7 +24,7 @@ import org.microg.nlp.AbstractProviderService;
import static org.microg.nlp.api.Constants.ACTION_RELOAD_SETTINGS;
public abstract class AbstractGeocodeService extends AbstractProviderService<GeocodeProvider> {
public static void reloadLocationService(Context context) {
public static void reloadGeocodeService(Context context) {
Intent intent = new Intent(ACTION_RELOAD_SETTINGS);
intent.setClass(context, GeocodeServiceV1.class);
context.startService(intent);

View file

@ -16,11 +16,14 @@
package org.microg.nlp.ui;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.os.IBinder;
import android.preference.DialogPreference;
import android.util.AttributeSet;
import android.view.LayoutInflater;
@ -37,7 +40,10 @@ import org.microg.nlp.R;
import java.util.ArrayList;
import java.util.List;
import static android.content.Context.BIND_AUTO_CREATE;
import static android.content.Intent.ACTION_VIEW;
import static org.microg.nlp.api.Constants.METADATA_BACKEND_ABOUT_ACTIVITY;
import static org.microg.nlp.api.Constants.METADATA_BACKEND_INIT_ACTIVITY;
import static org.microg.nlp.api.Constants.METADATA_BACKEND_SETTINGS_ACTIVITY;
import static org.microg.nlp.api.Constants.METADATA_BACKEND_SUMMARY;
@ -126,7 +132,7 @@ abstract class AbstractBackendPreference extends DialogPreference {
}
private Intent createExternalIntent(BackendInfo backendInfo, String metaName) {
Intent intent = new Intent(Intent.ACTION_VIEW);
Intent intent = new Intent(ACTION_VIEW);
intent.setPackage(backendInfo.serviceInfo.packageName);
intent.setClassName(backendInfo.serviceInfo.packageName, backendInfo.getMeta(metaName));
return intent;
@ -166,6 +172,7 @@ abstract class AbstractBackendPreference extends DialogPreference {
@Override
public void onClick(View v) {
backend.enabled = checkbox.isChecked();
if (backend.enabled) enableBackend(backend);
}
});
configureExternalButton(backend, v.findViewById(android.R.id.button1),
@ -191,6 +198,31 @@ abstract class AbstractBackendPreference extends DialogPreference {
}
}
protected void enableBackend(BackendInfo backendInfo) {
if (backendInfo.getMeta(METADATA_BACKEND_INIT_ACTIVITY) != null) {
getContext().startActivity(createExternalIntent(backendInfo, METADATA_BACKEND_INIT_ACTIVITY));
} else {
Intent intent = buildBackendIntent();
intent.setPackage(backendInfo.serviceInfo.packageName);
intent.setClassName(backendInfo.serviceInfo.packageName, backendInfo.serviceInfo.name);
getContext().bindService(intent, new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
Intent i = getBackendInitIntent(service);
if (i != null) {
getContext().startActivity(i);
}
getContext().unbindService(this);
}
@Override
public void onServiceDisconnected(ComponentName name) {
}
}, BIND_AUTO_CREATE);
}
}
@Override
protected void onDialogClosed(boolean positiveResult) {
if (positiveResult) {
@ -205,6 +237,8 @@ abstract class AbstractBackendPreference extends DialogPreference {
protected abstract String defaultValue();
protected abstract Intent getBackendInitIntent(IBinder service);
private class BackendInfo {
private final ServiceInfo serviceInfo;
private final String simpleName;

View file

@ -18,10 +18,13 @@ package org.microg.nlp.ui;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.AttributeSet;
import org.microg.nlp.Preferences;
import org.microg.nlp.R;
import org.microg.nlp.api.GeocoderBackend;
import org.microg.nlp.geocode.AbstractGeocodeService;
import static org.microg.nlp.api.Constants.ACTION_GEOCODER_BACKEND;
@ -35,7 +38,7 @@ public class GeocoderBackendPreference extends AbstractBackendPreference {
@Override
protected void onValueChanged() {
AbstractGeocodeService.reloadLocationService(getContext());
AbstractGeocodeService.reloadGeocodeService(getContext());
}
@Override
@ -47,4 +50,14 @@ public class GeocoderBackendPreference extends AbstractBackendPreference {
protected String defaultValue() {
return new Preferences(getContext()).getDefaultGeocoderBackends();
}
@Override
protected Intent getBackendInitIntent(IBinder service) {
GeocoderBackend backend = GeocoderBackend.Stub.asInterface(service);
try {
return backend.getInitIntent();
} catch (RemoteException e) {
return null;
}
}
}

View file

@ -18,10 +18,14 @@ package org.microg.nlp.ui;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.AttributeSet;
import org.microg.nlp.Preferences;
import org.microg.nlp.R;
import org.microg.nlp.api.GeocoderBackend;
import org.microg.nlp.api.LocationBackend;
import org.microg.nlp.location.AbstractLocationService;
import static org.microg.nlp.api.Constants.ACTION_LOCATION_BACKEND;
@ -47,4 +51,14 @@ public class LocationBackendPreference extends AbstractBackendPreference {
protected String defaultValue() {
return new Preferences(getContext()).getDefaultLocationBackends();
}
@Override
protected Intent getBackendInitIntent(IBinder service) {
LocationBackend backend = LocationBackend.Stub.asInterface(service);
try {
return backend.getInitIntent();
} catch (RemoteException e) {
return null;
}
}
}