• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.incallui.answer.impl.hint;
18 
19 import android.content.Context;
20 import android.content.SharedPreferences;
21 import android.graphics.drawable.Drawable;
22 import android.support.annotation.NonNull;
23 import android.support.annotation.Nullable;
24 import com.android.dialer.common.Assert;
25 import com.android.dialer.common.LogUtil;
26 import com.android.dialer.storage.StorageComponent;
27 import com.android.incallui.answer.impl.hint.PawSecretCodeListener.PawType;
28 
29 /** Decrypt the event payload to be shown if in a specific time range and the key is received. */
30 public final class PawImageLoaderImpl implements PawImageLoader {
31 
32   @Override
33   @Nullable
loadPayload(@onNull Context context)34   public Drawable loadPayload(@NonNull Context context) {
35     Assert.isNotNull(context);
36 
37     SharedPreferences preferences = StorageComponent.get(context).unencryptedSharedPrefs();
38     if (!preferences.getBoolean(PawSecretCodeListener.PAW_ENABLED_WITH_SECRET_CODE_KEY, false)) {
39       return null;
40     }
41     @PawType
42     int pawType =
43         preferences.getInt(PawSecretCodeListener.PAW_TYPE, PawSecretCodeListener.PAW_TYPE_INVALID);
44 
45     if (pawType == PawSecretCodeListener.PAW_TYPE_INVALID) {
46       LogUtil.i("PawImageLoaderImpl.loadPayload", "paw type not found, rerolling");
47       PawSecretCodeListener.selectPawType(preferences);
48       pawType =
49           preferences.getInt(
50               PawSecretCodeListener.PAW_TYPE, PawSecretCodeListener.PAW_TYPE_INVALID);
51     }
52 
53     switch (pawType) {
54       case PawSecretCodeListener.PAW_TYPE_CAT:
55         return context.getDrawable(R.drawable.cat_paw);
56       case PawSecretCodeListener.PAW_TYPE_DOG:
57         return context.getDrawable(R.drawable.dog_paw);
58       default:
59         throw Assert.createAssertionFailException("unknown paw type " + pawType);
60     }
61   }
62 }
63