Home | History | Annotate | Download | only in hint
      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.util.DialerUtils;
     28 
     29 /** Decrypt the event payload to be shown if in a specific time range and the key is received. */
     30 @TargetApi(VERSION_CODES.M)
     31 public final class PawImageLoaderImpl implements PawImageLoader {
     32 
     33   @Override
     34   @Nullable
     35   public Drawable loadPayload(@NonNull Context context) {
     36     Assert.isNotNull(context);
     37 
     38     SharedPreferences preferences =
     39         DialerUtils.getDefaultSharedPreferenceForDeviceProtectedStorageContext(context);
     40     if (!preferences.getBoolean(PawSecretCodeListener.PAW_ENABLED_WITH_SECRET_CODE_KEY, false)) {
     41       return null;
     42     }
     43     int drawableId = preferences.getInt(PawSecretCodeListener.PAW_DRAWABLE_ID_KEY, 0);
     44     if (drawableId == 0) {
     45       return null;
     46     }
     47     return context.getDrawable(drawableId);
     48   }
     49 }
     50