improved ipc error handling

updated version
This commit is contained in:
Mariotaku Lee 2016-12-15 20:37:55 +08:00
parent 1879d2d9be
commit d765ef2185
4 changed files with 12 additions and 34 deletions

View File

@ -35,8 +35,8 @@ android {
applicationId "org.mariotaku.twidere" applicationId "org.mariotaku.twidere"
minSdkVersion 14 minSdkVersion 14
targetSdkVersion 25 targetSdkVersion 25
versionCode 240 versionCode 241
versionName '3.3.22' versionName '3.3.23'
multiDexEnabled true multiDexEnabled true
buildConfigField 'boolean', 'LEAK_CANARY_ENABLED', 'Boolean.parseBoolean("true")' buildConfigField 'boolean', 'LEAK_CANARY_ENABLED', 'Boolean.parseBoolean("true")'

View File

@ -27,10 +27,7 @@ import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;
import org.mariotaku.twidere.BuildConfig;
import org.mariotaku.twidere.IMediaUploader; import org.mariotaku.twidere.IMediaUploader;
import org.mariotaku.twidere.model.MediaUploadResult; import org.mariotaku.twidere.model.MediaUploadResult;
import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.model.ParcelableStatus;
@ -40,7 +37,6 @@ import org.mariotaku.twidere.model.UserKey;
import java.util.List; import java.util.List;
import static org.mariotaku.twidere.TwidereConstants.LOGTAG;
import static org.mariotaku.twidere.constant.IntentConstants.INTENT_ACTION_EXTENSION_UPLOAD_MEDIA; import static org.mariotaku.twidere.constant.IntentConstants.INTENT_ACTION_EXTENSION_UPLOAD_MEDIA;
public final class MediaUploaderInterface extends AbsServiceInterface<IMediaUploader> { public final class MediaUploaderInterface extends AbsServiceInterface<IMediaUploader> {
@ -58,13 +54,10 @@ public final class MediaUploaderInterface extends AbsServiceInterface<IMediaUplo
final String mediaJson = JsonSerializer.serialize(media, UploaderMediaItem.class); final String mediaJson = JsonSerializer.serialize(media, UploaderMediaItem.class);
return JsonSerializer.parse(iface.upload(statusJson, currentAccountKey.toString(), return JsonSerializer.parse(iface.upload(statusJson, currentAccountKey.toString(),
mediaJson), MediaUploadResult.class); mediaJson), MediaUploadResult.class);
} catch (final RemoteException e) { } catch (final Exception e) {
if (BuildConfig.DEBUG) { return MediaUploadResult.error(2, e.getMessage());
Log.w(LOGTAG, e);
} }
} }
return null;
}
public boolean callback(MediaUploadResult uploadResult, ParcelableStatus status) { public boolean callback(MediaUploadResult uploadResult, ParcelableStatus status) {
@ -74,13 +67,10 @@ public final class MediaUploaderInterface extends AbsServiceInterface<IMediaUplo
final String resultJson = JsonSerializer.serialize(uploadResult, MediaUploadResult.class); final String resultJson = JsonSerializer.serialize(uploadResult, MediaUploadResult.class);
final String statusJson = JsonSerializer.serialize(status, ParcelableStatus.class); final String statusJson = JsonSerializer.serialize(status, ParcelableStatus.class);
return iface.callback(resultJson, statusJson); return iface.callback(resultJson, statusJson);
} catch (final RemoteException e) { } catch (final Exception e) {
if (BuildConfig.DEBUG) {
Log.w(LOGTAG, e);
}
}
return false; return false;
} }
}
@Override @Override
protected IMediaUploader onServiceConnected(ComponentName service, IBinder obj) { protected IMediaUploader onServiceConnected(ComponentName service, IBinder obj) {

View File

@ -27,10 +27,7 @@ import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;
import org.mariotaku.twidere.BuildConfig;
import org.mariotaku.twidere.IStatusShortener; import org.mariotaku.twidere.IStatusShortener;
import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.model.ParcelableStatus;
import org.mariotaku.twidere.model.ParcelableStatusUpdate; import org.mariotaku.twidere.model.ParcelableStatusUpdate;
@ -39,7 +36,6 @@ import org.mariotaku.twidere.model.UserKey;
import java.util.List; import java.util.List;
import static org.mariotaku.twidere.TwidereConstants.LOGTAG;
import static org.mariotaku.twidere.constant.IntentConstants.INTENT_ACTION_EXTENSION_SHORTEN_STATUS; import static org.mariotaku.twidere.constant.IntentConstants.INTENT_ACTION_EXTENSION_SHORTEN_STATUS;
public final class StatusShortenerInterface extends AbsServiceInterface<IStatusShortener> { public final class StatusShortenerInterface extends AbsServiceInterface<IStatusShortener> {
@ -63,13 +59,10 @@ public final class StatusShortenerInterface extends AbsServiceInterface<IStatusS
final String resultJson = iface.shorten(statusJson, currentAccountId.toString(), final String resultJson = iface.shorten(statusJson, currentAccountId.toString(),
overrideStatusText); overrideStatusText);
return JsonSerializer.parse(resultJson, StatusShortenResult.class); return JsonSerializer.parse(resultJson, StatusShortenResult.class);
} catch (final RemoteException e) { } catch (final Exception e) {
if (BuildConfig.DEBUG) { return StatusShortenResult.error(2, e.getMessage());
Log.w(LOGTAG, e);
} }
} }
return null;
}
public boolean callback(StatusShortenResult result, ParcelableStatus status) { public boolean callback(StatusShortenResult result, ParcelableStatus status) {
final IStatusShortener iface = getInterface(); final IStatusShortener iface = getInterface();
@ -78,13 +71,10 @@ public final class StatusShortenerInterface extends AbsServiceInterface<IStatusS
final String resultJson = JsonSerializer.serialize(result, StatusShortenResult.class); final String resultJson = JsonSerializer.serialize(result, StatusShortenResult.class);
final String statusJson = JsonSerializer.serialize(status, ParcelableStatus.class); final String statusJson = JsonSerializer.serialize(status, ParcelableStatus.class);
return iface.callback(resultJson, statusJson); return iface.callback(resultJson, statusJson);
} catch (final RemoteException e) { } catch (final Exception e) {
if (BuildConfig.DEBUG) {
Log.w(LOGTAG, e);
}
}
return false; return false;
} }
}
public static StatusShortenerInterface getInstance(final Application application, final String shortenerName) { public static StatusShortenerInterface getInstance(final Application application, final String shortenerName) {
if (shortenerName == null) return null; if (shortenerName == null) return null;

View File

@ -387,13 +387,11 @@ class UpdateStatusTask(
throw ExtensionVersionMismatchException() throw ExtensionVersionMismatchException()
} }
} }
} catch (e: AbsServiceInterface.CheckServiceException) { } catch (e: ExtensionVersionMismatchException) {
if (e is ExtensionVersionMismatchException) {
throw ShortenException(context.getString(R.string.shortener_version_incompatible)) throw ShortenException(context.getString(R.string.shortener_version_incompatible))
} } catch (e: AbsServiceInterface.CheckServiceException) {
throw ShortenException(e) throw ShortenException(e)
} }
return shortener return shortener
} }