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"
minSdkVersion 14
targetSdkVersion 25
versionCode 240
versionName '3.3.22'
versionCode 241
versionName '3.3.23'
multiDexEnabled 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.os.Bundle;
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.model.MediaUploadResult;
import org.mariotaku.twidere.model.ParcelableStatus;
@ -40,7 +37,6 @@ import org.mariotaku.twidere.model.UserKey;
import java.util.List;
import static org.mariotaku.twidere.TwidereConstants.LOGTAG;
import static org.mariotaku.twidere.constant.IntentConstants.INTENT_ACTION_EXTENSION_UPLOAD_MEDIA;
public final class MediaUploaderInterface extends AbsServiceInterface<IMediaUploader> {
@ -58,12 +54,9 @@ public final class MediaUploaderInterface extends AbsServiceInterface<IMediaUplo
final String mediaJson = JsonSerializer.serialize(media, UploaderMediaItem.class);
return JsonSerializer.parse(iface.upload(statusJson, currentAccountKey.toString(),
mediaJson), MediaUploadResult.class);
} catch (final RemoteException e) {
if (BuildConfig.DEBUG) {
Log.w(LOGTAG, e);
}
} catch (final Exception e) {
return MediaUploadResult.error(2, e.getMessage());
}
return null;
}
@ -74,12 +67,9 @@ public final class MediaUploaderInterface extends AbsServiceInterface<IMediaUplo
final String resultJson = JsonSerializer.serialize(uploadResult, MediaUploadResult.class);
final String statusJson = JsonSerializer.serialize(status, ParcelableStatus.class);
return iface.callback(resultJson, statusJson);
} catch (final RemoteException e) {
if (BuildConfig.DEBUG) {
Log.w(LOGTAG, e);
}
} catch (final Exception e) {
return false;
}
return false;
}
@Override

View File

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

View File

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