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,12 +54,9 @@ 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;
} }
@ -74,12 +67,9 @@ 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) { return false;
Log.w(LOGTAG, e);
}
} }
return false;
} }
@Override @Override

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,12 +59,9 @@ 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) {
@ -78,12 +71,9 @@ 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) { return false;
Log.w(LOGTAG, e);
}
} }
return false;
} }
public static StatusShortenerInterface getInstance(final Application application, final String shortenerName) { public static StatusShortenerInterface getInstance(final Application application, final String shortenerName) {

View File

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