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