Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 80257cce authored by Michael W's avatar Michael W Committed by Michael Bestas
Browse files

Dialer: Remove CallLocation

* We only have a stub implementation, so the code doesn't do much

Change-Id: I340e2177119d72813697403f6124ed0f130465f4
parent 68883dd4
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@ import com.android.dialer.promotion.impl.PromotionModule;
import com.android.dialer.simulator.impl.SimulatorModule;
import com.android.dialer.storage.StorageModule;
import com.android.dialer.theme.base.impl.AospThemeModule;
import com.android.incallui.calllocation.stub.StubCallLocationModule;
import com.android.voicemail.impl.VoicemailModule;
import dagger.Component;
import javax.inject.Singleton;
@@ -54,7 +53,6 @@ import javax.inject.Singleton;
      PromotionModule.class,
      SimulatorModule.class,
      StorageModule.class,
      StubCallLocationModule.class,
      StubSimSuggestionModule.class,
      AospThemeModule.class,
      VoicemailModule.class,
+0 −2
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@ import com.android.dialer.simulator.SimulatorComponent;
import com.android.dialer.speeddial.loader.UiItemLoaderComponent;
import com.android.dialer.storage.StorageComponent;
import com.android.dialer.theme.base.ThemeComponent;
import com.android.incallui.calllocation.CallLocationComponent;
import com.android.voicemail.VoicemailComponent;

/**
@@ -43,7 +42,6 @@ import com.android.voicemail.VoicemailComponent;
 */
public interface BaseDialerRootComponent
    extends ActiveCallsComponent.HasComponent,
        CallLocationComponent.HasComponent,
        CallLogComponent.HasComponent,
        CallLogDatabaseComponent.HasComponent,
        CallLogUiComponent.HasComponent,
+1 −100
Original line number Diff line number Diff line
@@ -21,12 +21,10 @@ import static com.android.contacts.common.compat.CallCompat.Details.PROPERTY_ENT
import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.hardware.display.DisplayManager;
import android.os.BatteryManager;
import android.os.Handler;
import android.os.Trace;
import android.support.v4.app.Fragment;
@@ -42,7 +40,6 @@ import android.view.View;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.android.contacts.common.ContactsUtils;
@@ -66,8 +63,6 @@ import com.android.incallui.call.CallList;
import com.android.incallui.call.DialerCall;
import com.android.incallui.call.DialerCallListener;
import com.android.incallui.call.state.DialerCallState;
import com.android.incallui.calllocation.CallLocation;
import com.android.incallui.calllocation.CallLocationComponent;
import com.android.incallui.incall.protocol.ContactPhotoType;
import com.android.incallui.incall.protocol.InCallScreen;
import com.android.incallui.incall.protocol.InCallScreenDelegate;
@@ -119,8 +114,6 @@ public class CallCardPresenter
  private boolean isInCallScreenReady;
  private boolean shouldSendAccessibilityEvent;

  @NonNull
  private final CallLocation callLocation;
  private final Runnable sendAccessibilityEventRunnable =
      new Runnable() {
        @Override
@@ -139,7 +132,6 @@ public class CallCardPresenter
  public CallCardPresenter(Context context) {
    LogUtil.i("CallCardPresenter.constructor", null);
    this.context = Assert.isNotNull(context).getApplicationContext();
    callLocation = CallLocationComponent.get(this.context).getCallLocation();
  }

  private static boolean hasCallSubject(DialerCall call) {
@@ -186,11 +178,6 @@ public class CallCardPresenter
    InCallPresenter.getInstance().addDetailsListener(this);
    InCallPresenter.getInstance().addInCallEventListener(this);
    isInCallScreenReady = true;

    // Showing the location may have been skipped if the UI wasn't ready during previous layout.
    if (shouldShowLocation()) {
      inCallScreen.showLocationUi(getLocationFragment());
    }
  }

  @Override
@@ -207,8 +194,6 @@ public class CallCardPresenter
      primary.removeListener(this);
    }

    callLocation.close();

    primary = null;
    primaryContactInfo = null;
    secondaryContactInfo = null;
@@ -642,7 +627,6 @@ public class CallCardPresenter
              .setIsSpam(false)
              .setIsLocalContact(false)
              .setAnsweringDisconnectsOngoingCall(false)
              .setShouldShowLocation(shouldShowLocation())
              .setShowInCallButtonGrid(true)
              .setNumberPresentation(primary.getNumberPresentation())
              .build());
@@ -692,7 +676,6 @@ public class CallCardPresenter
              .setIsSpam(primary.isSpam())
              .setIsLocalContact(primaryContactInfo.isLocalContact())
              .setAnsweringDisconnectsOngoingCall(primary.answeringDisconnectsForegroundVideoCall())
              .setShouldShowLocation(shouldShowLocation())
              .setContactInfoLookupKey(primaryContactInfo.lookupKey)
              .setMultimediaData(multimediaData)
              .setShowInCallButtonGrid(true)
@@ -704,7 +687,7 @@ public class CallCardPresenter
    }

    if (isInCallScreenReady) {
      inCallScreen.showLocationUi(getLocationFragment());
      inCallScreen.showLocationUi(null);
    } else {
      LogUtil.i("CallCardPresenter.updatePrimaryDisplayInfo", "UI not ready, not showing location");
    }
@@ -721,88 +704,6 @@ public class CallCardPresenter
    return false;
  }

  private Fragment getLocationFragment() {
    if (!shouldShowLocation()) {
      return null;
    }
    LogUtil.i("CallCardPresenter.getLocationFragment", "returning location fragment");
    return callLocation.getLocationFragment(context);
  }

  private boolean shouldShowLocation() {
    if (!isPotentialEmergencyCall()) {
      LogUtil.i("CallCardPresenter.getLocationFragment", "shouldn't show location");
      return false;
    }
    if (!hasLocationPermission()) {
      LogUtil.i("CallCardPresenter.getLocationFragment", "no location permission.");
      return false;
    }
    if (isBatteryTooLowForEmergencyLocation()) {
      LogUtil.i("CallCardPresenter.getLocationFragment", "low battery.");
      return false;
    }
    if (inCallScreen.getInCallScreenFragment().getActivity().isInMultiWindowMode()) {
      LogUtil.i("CallCardPresenter.getLocationFragment", "in multi-window mode");
      return false;
    }
    if (primary.isVideoCall()) {
      LogUtil.i("CallCardPresenter.getLocationFragment", "emergency video calls not supported");
      return false;
    }
    if (!callLocation.canGetLocation(context)) {
      LogUtil.i("CallCardPresenter.getLocationFragment", "can't get current location");
      return false;
    }
    return true;
  }

  private boolean isPotentialEmergencyCall() {
    if (isOutgoingEmergencyCall(primary)) {
      LogUtil.i("CallCardPresenter.shouldShowLocation", "new emergency call");
      return true;
    } else if (isIncomingEmergencyCall(primary)) {
      LogUtil.i("CallCardPresenter.shouldShowLocation", "potential emergency callback");
      return true;
    } else if (isIncomingEmergencyCall(secondary)) {
      LogUtil.i("CallCardPresenter.shouldShowLocation", "has potential emergency callback");
      return true;
    }
    return false;
  }

  private static boolean isOutgoingEmergencyCall(@Nullable DialerCall call) {
    return call != null && !call.isIncoming() && call.isEmergencyCall();
  }

  private static boolean isIncomingEmergencyCall(@Nullable DialerCall call) {
    return call != null && call.isIncoming() && call.isPotentialEmergencyCallback();
  }

  private boolean hasLocationPermission() {
    return ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION)
        == PackageManager.PERMISSION_GRANTED;
  }

  private boolean isBatteryTooLowForEmergencyLocation() {
    Intent batteryStatus =
        context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
    int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
    if (status == BatteryManager.BATTERY_STATUS_CHARGING
        || status == BatteryManager.BATTERY_STATUS_FULL) {
      // Plugged in or full battery
      return false;
    }
    int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
    int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
    float batteryPercent = (100f * level) / scale;
    long threshold = CONFIG_MIN_BATTERY_PERCENT_FOR_EMERGENCY_LOCATION_DEFAULT;
    LogUtil.i(
        "CallCardPresenter.isBatteryTooLowForEmergencyLocation",
        "percent charged: " + batteryPercent + ", min required charge: " + threshold);
    return batteryPercent < threshold;
  }

  private void updateSecondaryDisplayInfo() {
    if (inCallScreen == null) {
      return;
+0 −5
Original line number Diff line number Diff line
@@ -535,11 +535,6 @@ public class AnswerFragment extends Fragment
        .setContactPhoto(
            primaryInfo.photoType() == ContactPhotoType.CONTACT ? primaryInfo.photo() : null);
    updateDataFragment();

    if (primaryInfo.shouldShowLocation()) {
      // Hide the avatar to make room for location
      contactGridManager.setAvatarHidden(true);
    }
  }

  private void updateDataFragment() {
+0 −33
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

package com.android.incallui.calllocation;

import android.content.Context;
import android.support.v4.app.Fragment;

import androidx.annotation.NonNull;

/** Used to show the user's location during an emergency call. */
public interface CallLocation {

  boolean canGetLocation(@NonNull Context context);

  @NonNull
  Fragment getLocationFragment(@NonNull Context context);

  void close();
}
Loading