android.os.Parcel.readException()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(704)

本文整理了Java中android.os.Parcel.readException()方法的一些代码示例,展示了Parcel.readException()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Parcel.readException()方法的具体详情如下:
包路径:android.os.Parcel
类名称:Parcel
方法名:readException

Parcel.readException介绍

[英]Special function for reading an exception result from the header of a parcel, to be used after receiving the result of a transaction. This will throw the exception for you if it had been written to the Parcel, otherwise return and let you read the normal result data from the Parcel.
[中]用于从包裹头读取异常结果的特殊功能,在收到交易结果后使用。如果异常已写入包裹,这将为您抛出异常,否则返回并让您从包裹中读取正常结果数据。

代码示例

代码示例来源:origin: facebook/facebook-android-sdk

public boolean isTrackingLimited() throws RemoteException {
    Parcel data = Parcel.obtain();
    Parcel reply = Parcel.obtain();
    boolean limitAdTracking;
    try {
      data.writeInterfaceToken(
          "com.google.android.gms.ads.identifier.internal.IAdvertisingIdService");
      data.writeInt(1);
      binder.transact(SECOND_TRANSACTION_CODE, data, reply, 0);
      reply.readException();
      limitAdTracking = 0 != reply.readInt();
    } finally {
      reply.recycle();
      data.recycle();
    }
    return limitAdTracking;
  }
}

代码示例来源:origin: android-hacker/VirtualXposed

@Override
public int enqueue(android.app.job.JobInfo job, android.app.job.JobWorkItem work) throws android.os.RemoteException {
  android.os.Parcel _data = android.os.Parcel.obtain();
  android.os.Parcel _reply = android.os.Parcel.obtain();
  int _result;
  try {
    _data.writeInterfaceToken(DESCRIPTOR);
    if ((job != null)) {
      _data.writeInt(1);
      job.writeToParcel(_data, 0);
    } else {
      _data.writeInt(0);
    }
    if ((work != null)) {
      _data.writeInt(1);
      work.writeToParcel(_data, 0);
    } else {
      _data.writeInt(0);
    }
    mRemote.transact(Stub.TRANSACTION_enqueue, _data, _reply, 0);
    _reply.readException();
    _result = _reply.readInt();
  } finally {
    _reply.recycle();
    _data.recycle();
  }
  return _result;
}

代码示例来源:origin: android-hacker/VirtualXposed

@Override
public int schedule(android.app.job.JobInfo job) throws android.os.RemoteException {
  android.os.Parcel _data = android.os.Parcel.obtain();
  android.os.Parcel _reply = android.os.Parcel.obtain();
  int _result;
  try {
    _data.writeInterfaceToken(DESCRIPTOR);
    if ((job != null)) {
      _data.writeInt(1);
      job.writeToParcel(_data, 0);
    } else {
      _data.writeInt(0);
    }
    mRemote.transact(Stub.TRANSACTION_schedule, _data, _reply, 0);
    _reply.readException();
    _result = _reply.readInt();
  } finally {
    _reply.recycle();
    _data.recycle();
  }
  return _result;
}

代码示例来源:origin: android-hacker/VirtualXposed

@Override
public void cancel(int jobId) throws android.os.RemoteException {
  android.os.Parcel _data = android.os.Parcel.obtain();
  android.os.Parcel _reply = android.os.Parcel.obtain();
  try {
    _data.writeInterfaceToken(DESCRIPTOR);
    _data.writeInt(jobId);
    mRemote.transact(Stub.TRANSACTION_cancel, _data, _reply, 0);
    _reply.readException();
  } finally {
    _reply.recycle();
    _data.recycle();
  }
}

代码示例来源:origin: firebase/firebase-jobdispatcher-android

@Override
 public void jobFinished(@JobService.JobResult int status) {
  Parcel request = Parcel.obtain();
  Parcel response = Parcel.obtain();
  try {
   request.writeInterfaceToken(DESCRIPTOR);
   request.writeInt(status);

   remote.transact(TRANSACTION_TASK_FINISHED, request, response, 0);

   response.readException();
  } catch (RemoteException e) {
   throw new RuntimeException(e);
  } finally {
   request.recycle();
   response.recycle();
  }
 }
}

代码示例来源:origin: facebook/facebook-android-sdk

public String getAdvertiserId() throws RemoteException {
  Parcel data = Parcel.obtain();
  Parcel reply = Parcel.obtain();
  String id;
  try {
    data.writeInterfaceToken(
        "com.google.android.gms.ads.identifier.internal.IAdvertisingIdService");
    binder.transact(FIRST_TRANSACTION_CODE, data, reply, 0);
    reply.readException();
    id = reply.readString();
  } finally {
    reply.recycle();
    data.recycle();
  }
  return id;
}

代码示例来源:origin: android-hacker/VirtualXposed

@Override
  public android.app.job.JobInfo getPendingJob(int i) throws android.os.RemoteException {
    android.os.Parcel _data = android.os.Parcel.obtain();
    android.os.Parcel _reply = android.os.Parcel.obtain();
    android.app.job.JobInfo _result;
    try {
      _data.writeInterfaceToken(DESCRIPTOR);
      _data.writeInt(i);
      mRemote.transact(Stub.TRANSACTION_getPendingJob, _data, _reply, 0);
      _reply.readException();
      if ((0 != _reply.readInt())) {
        _result = android.app.job.JobInfo.CREATOR.createFromParcel(_reply);
      } else {
        _result = null;
      }
    } finally {
      _reply.recycle();
      _data.recycle();
    }
    return _result;
  }
}

代码示例来源:origin: android-hacker/VirtualXposed

@Override
public void cancelAll() throws android.os.RemoteException {
  android.os.Parcel _data = android.os.Parcel.obtain();
  android.os.Parcel _reply = android.os.Parcel.obtain();
  try {
    _data.writeInterfaceToken(DESCRIPTOR);
    mRemote.transact(Stub.TRANSACTION_cancelAll, _data, _reply, 0);
    _reply.readException();
  } finally {
    _reply.recycle();
    _data.recycle();
  }
}

代码示例来源:origin: robolectric/robolectric

@Test
public void transactCallsOnTransact() throws Exception {
 TestBinder testBinder = new TestBinder();
 Parcel data = Parcel.obtain();
 Parcel reply = Parcel.obtain();
 data.writeString("Hello Robolectric");
 assertTrue(testBinder.transact(2, data, reply, 3));
 assertThat(testBinder.code).isEqualTo(2);
 assertThat(testBinder.data).isSameAs(data);
 assertThat(testBinder.reply).isSameAs(reply);
 assertThat(testBinder.flags).isEqualTo(3);
 reply.readException();
 assertThat(reply.readString()).isEqualTo("Hello Robolectric");
}

代码示例来源:origin: android-hacker/VirtualXposed

@Override
public java.util.List<android.app.job.JobInfo> getAllPendingJobs() throws android.os.RemoteException {
  android.os.Parcel _data = android.os.Parcel.obtain();
  android.os.Parcel _reply = android.os.Parcel.obtain();
  java.util.List<android.app.job.JobInfo> _result;
  try {
    _data.writeInterfaceToken(DESCRIPTOR);
    mRemote.transact(Stub.TRANSACTION_getAllPendingJobs, _data, _reply, 0);
    _reply.readException();
    _result = _reply.createTypedArrayList(android.app.job.JobInfo.CREATOR);
  } finally {
    _reply.recycle();
    _data.recycle();
  }
  return _result;
}

代码示例来源:origin: robolectric/robolectric

@Test
public void thrownExceptionIsParceled() throws Exception {
 TestThrowingBinder testThrowingBinder = new TestThrowingBinder();
 Parcel data = Parcel.obtain();
 Parcel reply = Parcel.obtain();
 testThrowingBinder.transact(2, data, reply, 3);
 try {
  reply.readException();
  fail();  // Expect thrown
 } catch (SecurityException e) {
  assertThat(e.getMessage()).isEqualTo("Halt! Who goes there?");
 }
}

代码示例来源:origin: stackoverflow.com

public boolean handleApplicationWtf(IBinder app, String tag,
    ApplicationErrorReport.CrashInfo crashInfo)
    throws RemoteException {
  Parcel data = Parcel.obtain();
  Parcel reply = Parcel.obtain();
  data.writeInterfaceToken(IActivityManager.descriptor);
  data.writeStrongBinder(app);
  data.writeString(tag);
  crashInfo.writeToParcel(data, 0);
  mRemote.transact(HANDLE_APPLICATION_WTF_TRANSACTION, data,
      reply, 0);
  reply.readException();
  boolean res = reply.readInt() != 0;
  reply.recycle();
  data.recycle();
  return res;
}

代码示例来源:origin: limpoxe/Android-Plugin-Framework

/**
   * Demonstrates some basic types that you can use as parameters
   * and return values in AIDL.
   */
@Override public void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat, double aDouble, String aString) throws android.os.RemoteException
{
android.os.Parcel _data = android.os.Parcel.obtain();
android.os.Parcel _reply = android.os.Parcel.obtain();
try {
_data.writeInterfaceToken(DESCRIPTOR);
_data.writeInt(anInt);
_data.writeLong(aLong);
_data.writeInt(((aBoolean)?(1):(0)));
_data.writeFloat(aFloat);
_data.writeDouble(aDouble);
_data.writeString(aString);
mRemote.transact(Stub.TRANSACTION_basicTypes, _data, _reply, 0);
_reply.readException();
}
finally {
_reply.recycle();
_data.recycle();
}
}
}

代码示例来源:origin: stackoverflow.com

2749    public boolean isUserAMonkey() throws RemoteException {
2750        Parcel data = Parcel.obtain();
2751        Parcel reply = Parcel.obtain();
2752        data.writeInterfaceToken(IActivityManager.descriptor);
2753        mRemote.transact(IS_USER_A_MONKEY_TRANSACTION, data, reply, 0);
2754        reply.readException();
2755        boolean res = reply.readInt() != 0;
2756        data.recycle();
2757        reply.recycle();
2758        return res;
2759    }

代码示例来源:origin: shyluo/CrashImmuneDecoder

public void onError(int code) throws RemoteException {
  Parcel data = Parcel.obtain();
  Parcel reply = Parcel.obtain();
  try {
    data.writeInterfaceToken(DESCRIPTION);
    data.writeInt(code);
    remote.transact(ON_ERROR_TRANSACTION, data, reply, IBinder.FLAG_ONEWAY);
    reply.readException();
  } finally {
    reply.recycle();
    data.recycle();
  }
}

代码示例来源:origin: MoMoWait/LeanbackLauncher

public void dismissRecommendation(String key) throws RemoteException {
  Parcel _data = Parcel.obtain();
  Parcel _reply = Parcel.obtain();
  try {
    _data.writeInterfaceToken("com.rockchips.android.tvrecommendations.IRecommendationsService");
    _data.writeString(key);
    this.mRemote.transact(6, _data, _reply, 0);
    _reply.readException();
  } finally {
    _reply.recycle();
    _data.recycle();
  }
}

代码示例来源:origin: stackoverflow.com

public void activityPaused(IBinder token, Bundle state) throws RemoteException
{
  Parcel data = Parcel.obtain();
  Parcel reply = Parcel.obtain();
  data.writeInterfaceToken(IActivityManager.descriptor);
  data.writeStrongBinder(token);
  data.writeBundle(state);
  mRemote.transact(ACTIVITY_PAUSED_TRANSACTION, data, reply, 0);
  reply.readException();
  data.recycle();
  reply.recycle();
}

代码示例来源:origin: shyluo/CrashImmuneDecoder

public void release() throws RemoteException {
    Parcel data = Parcel.obtain();
    Parcel reply = Parcel.obtain();

    try {
      data.writeInterfaceToken(DESCRIPTION);

      remote.transact(RELEASE_TRANSACTION, data, reply, 0);

      reply.readException();
    } finally {
      reply.recycle();
      data.recycle();
    }
  }
}

代码示例来源:origin: klinker41/android-smsmms

@Override
public void registerListener(android.net.INetworkPolicyListener listener) throws android.os.RemoteException {
  android.os.Parcel _data = android.os.Parcel.obtain();
  android.os.Parcel _reply = android.os.Parcel.obtain();
  try {
    _data.writeInterfaceToken(DESCRIPTOR);
    _data.writeStrongBinder((((listener != null)) ? (listener.asBinder()) : (null)));
    mRemote.transact(Stub.TRANSACTION_registerListener, _data, _reply, 0);
    _reply.readException();
  } finally {
    _reply.recycle();
    _data.recycle();
  }
}

代码示例来源:origin: shyluo/CrashImmuneDecoder

public void setCallback(IVideoDecoderCallback callback) throws RemoteException {
  Parcel data = Parcel.obtain();
  Parcel reply = Parcel.obtain();
  try {
    data.writeInterfaceToken(DESCRIPTION);
    data.writeStrongBinder(callback.asBinder());
    remote.transact(SET_CALLBACK_TRANSACTION, data, reply, 0);
    reply.readException();
  } finally {
    reply.recycle();
    data.recycle();
  }
}

相关文章

Parcel类方法