Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package android.os.cts;
     18 
     19 import android.app.PendingIntent;
     20 import android.app.AuthenticationRequiredException;
     21 import android.app.Service;
     22 import android.content.Intent;
     23 import android.os.Binder;
     24 import android.os.IBinder;
     25 import android.os.Parcel;
     26 import android.os.Parcelable;
     27 
     28 import java.io.FileDescriptor;
     29 import java.io.FileNotFoundException;
     30 
     31 public class CrossProcessExceptionService extends Service {
     32     public static class CustomException extends IllegalArgumentException implements Parcelable {
     33         public CustomException(String message) {
     34             super(message);
     35         }
     36 
     37         @Override
     38         public int describeContents() {
     39             return 0;
     40         }
     41 
     42         @Override
     43         public void writeToParcel(Parcel dest, int flags) {
     44         }
     45 
     46         public static final Creator<CustomException> CREATOR = new Creator<CustomException>() {
     47             @Override
     48             public CustomException createFromParcel(Parcel source) {
     49                 return new CustomException("REMOTE");
     50             }
     51 
     52             @Override
     53             public CustomException[] newArray(int size) {
     54                 return new CustomException[size];
     55             }
     56         };
     57 
     58     }
     59 
     60     @Override
     61     public IBinder onBind(Intent intent) {
     62         return new Binder() {
     63             @Override
     64             public void dump(FileDescriptor fd, String[] args) {
     65                 switch (args[0]) {
     66                     case "none":
     67                         return;
     68                     case "SE":
     69                         throw new SecurityException("SE");
     70                     case "ARE":
     71                         final PendingIntent pi = PendingIntent.getActivity(
     72                                 CrossProcessExceptionService.this, 12, new Intent(),
     73                                 PendingIntent.FLAG_CANCEL_CURRENT);
     74                         throw new AuthenticationRequiredException(new FileNotFoundException("FNFE"), pi);
     75                     case "RE":
     76                         throw new RuntimeException("RE");
     77                     case "custom":
     78                         throw new CustomException("LOCAL");
     79                 }
     80             }
     81         };
     82     }
     83 }
     84