Merge pull request #10709 from osmandapp/modify_aidl_import

Add silent profile import from another app
This commit is contained in:
Vitaliy 2021-01-31 12:57:18 +02:00 committed by GitHub
commit 8e1923fc57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 11 deletions

View file

@ -8,6 +8,7 @@ import net.osmand.aidlapi.AidlParams;
import net.osmand.aidlapi.profile.AExportSettingsType;
import java.util.ArrayList;
import java.util.List;
import static net.osmand.aidlapi.profile.ExportProfileParams.SETTINGS_TYPE_KEY;
@ -15,16 +16,18 @@ public class ProfileSettingsParams extends AidlParams {
public static final String VERSION_KEY = "version";
public static final String REPLACE_KEY = "replace";
public static final String SILENT_IMPORT_KEY = "silent_import";
public static final String LATEST_CHANGES_KEY = "latestChanges";
public static final String PROFILE_SETTINGS_URI_KEY = "profileSettingsUri";
private Uri profileSettingsUri;
private String latestChanges;
private int version;
private ArrayList<String> settingsTypeKeyList = new ArrayList<>();
boolean replace;
private List<String> settingsTypeKeyList = new ArrayList<>();
private boolean silent;
private boolean replace;
public ProfileSettingsParams(Uri profileSettingsUri, ArrayList<AExportSettingsType> settingsTypeList, boolean replace,
String latestChanges, int version) {
public ProfileSettingsParams(Uri profileSettingsUri, List<AExportSettingsType> settingsTypeList, boolean replace,
boolean silent, String latestChanges, int version) {
this.profileSettingsUri = profileSettingsUri;
for (AExportSettingsType settingsType : settingsTypeList) {
settingsTypeKeyList.add(settingsType.name());
@ -32,6 +35,7 @@ public class ProfileSettingsParams extends AidlParams {
this.replace = replace;
this.latestChanges = latestChanges;
this.version = version;
this.silent = silent;
}
public ProfileSettingsParams(Parcel in) {
@ -62,7 +66,7 @@ public class ProfileSettingsParams extends AidlParams {
return profileSettingsUri;
}
public ArrayList<String> getSettingsTypeKeys() {
public List<String> getSettingsTypeKeys() {
return settingsTypeKeyList;
}
@ -70,13 +74,18 @@ public class ProfileSettingsParams extends AidlParams {
return replace;
}
public boolean isSilent() {
return silent;
}
@Override
public void writeToBundle(Bundle bundle) {
bundle.putInt(VERSION_KEY, version);
bundle.putString(LATEST_CHANGES_KEY, latestChanges);
bundle.putParcelable(PROFILE_SETTINGS_URI_KEY, profileSettingsUri);
bundle.putStringArrayList(SETTINGS_TYPE_KEY, settingsTypeKeyList);
bundle.putStringArrayList(SETTINGS_TYPE_KEY, new ArrayList<>(settingsTypeKeyList));
bundle.putBoolean(REPLACE_KEY, replace);
bundle.putBoolean(SILENT_IMPORT_KEY, silent);
}
@Override
@ -86,5 +95,6 @@ public class ProfileSettingsParams extends AidlParams {
profileSettingsUri = bundle.getParcelable(PROFILE_SETTINGS_URI_KEY);
settingsTypeKeyList = bundle.getStringArrayList(SETTINGS_TYPE_KEY);
replace = bundle.getBoolean(REPLACE_KEY);
silent = bundle.getBoolean(SILENT_IMPORT_KEY);
}
}

View file

@ -2296,13 +2296,13 @@ public class OsmandAidlApi {
return false;
}
public boolean importProfileV2(final Uri profileUri, ArrayList<String> settingsTypeKeys, boolean replace,
String latestChanges, int version) {
public boolean importProfileV2(final Uri profileUri, List<String> settingsTypeKeys, boolean replace,
boolean silent, String latestChanges, int version) {
if (profileUri != null) {
Bundle bundle = new Bundle();
bundle.putStringArrayList(SettingsHelper.SETTINGS_TYPE_LIST_KEY, settingsTypeKeys);
bundle.putStringArrayList(SettingsHelper.SETTINGS_TYPE_LIST_KEY, new ArrayList<>(settingsTypeKeys));
bundle.putBoolean(REPLACE_KEY, replace);
bundle.putBoolean(SILENT_IMPORT_KEY, true);
bundle.putBoolean(SILENT_IMPORT_KEY, silent);
bundle.putString(SettingsHelper.SETTINGS_LATEST_CHANGES_KEY, latestChanges);
bundle.putInt(SettingsHelper.SETTINGS_VERSION_KEY, version);

View file

@ -1270,7 +1270,7 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener
try {
OsmandAidlApi api = getApi("importProfile");
return api != null && api.importProfileV2(params.getProfileSettingsUri(), params.getSettingsTypeKeys(),
params.isReplace(), params.getLatestChanges(), params.getVersion());
params.isReplace(), params.isSilent(), params.getLatestChanges(), params.getVersion());
} catch (Exception e) {
handleException(e);
return false;