1 /* 2 * Copyright (C) 2016 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 com.android.dialer.callintent; 18 19 import android.os.Bundle; 20 import android.support.annotation.NonNull; 21 import android.support.annotation.Nullable; 22 import com.android.dialer.protos.ProtoParsers; 23 24 /** Parses data for a call extra to get any dialer specific app data. */ 25 public class CallIntentParser { 26 static final String EXTRA_CALL_SPECIFIC_APP_DATA_WRAPPER = 27 "com.android.dialer.callintent.CALL_SPECIFIC_APP_DATA_WRAPPER"; 28 @Nullable 29 public static CallSpecificAppData getCallSpecificAppData(@Nullable Bundle extras) { 30 if (extras == null) { 31 return null; 32 } 33 34 if (!extras.containsKey(Constants.EXTRA_CALL_SPECIFIC_APP_DATA)) { 35 return null; 36 } 37 38 return ProtoParsers.getTrusted( 39 extras.getBundle(Constants.EXTRA_CALL_SPECIFIC_APP_DATA), 40 EXTRA_CALL_SPECIFIC_APP_DATA_WRAPPER, 41 CallSpecificAppData.getDefaultInstance()); 42 } 43 44 public static void putCallSpecificAppData( 45 @NonNull Bundle extras, @NonNull CallSpecificAppData callSpecificAppData) { 46 // We wrap our bundle for consumers that may not have access to ProtoParsers in their class 47 // loader. This is necessary to prevent ClassNotFoundException's 48 Bundle wrapperBundle = new Bundle(); 49 ProtoParsers.put(wrapperBundle, EXTRA_CALL_SPECIFIC_APP_DATA_WRAPPER, callSpecificAppData); 50 extras.putBundle(Constants.EXTRA_CALL_SPECIFIC_APP_DATA, wrapperBundle); 51 } 52 53 private CallIntentParser() {} 54 } 55