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
17package com.android.dialer.callintent;
18
19import android.os.Bundle;
20import android.support.annotation.NonNull;
21import android.support.annotation.Nullable;
22import com.android.dialer.common.LogUtil;
23import com.android.dialer.protos.ProtoParsers;
24
25/** Parses data for a call extra to get any dialer specific app data. */
26public class CallIntentParser {
27
28
29  @Nullable
30  public static CallSpecificAppData getCallSpecificAppData(@Nullable Bundle extras) {
31    if (extras == null) {
32      return null;
33    }
34
35    if (!extras.containsKey(Constants.EXTRA_CALL_SPECIFIC_APP_DATA)) {
36      return null;
37    }
38
39    if (extras.getByteArray(Constants.EXTRA_CALL_SPECIFIC_APP_DATA) == null) {
40      LogUtil.i(
41          "CallIntentParser.getCallSpecificAppData",
42          "unexpected null byte array for call specific app data proto");
43      return null;
44    }
45
46    return ProtoParsers.getTrusted(
47        extras, Constants.EXTRA_CALL_SPECIFIC_APP_DATA, CallSpecificAppData.getDefaultInstance());
48  }
49
50  public static void putCallSpecificAppData(
51      @NonNull Bundle extras, @NonNull CallSpecificAppData callSpecificAppData) {
52    ProtoParsers.put(extras, Constants.EXTRA_CALL_SPECIFIC_APP_DATA, callSpecificAppData);
53  }
54
55  private CallIntentParser() {}
56}
57