Java Code Examples for org.telegram.tgnet.TLRPC#TL_inputPhoneCall

The following examples show how to use org.telegram.tgnet.TLRPC#TL_inputPhoneCall . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VoIPService.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void onControllerPreRelease(){
	if(needSendDebugLog){
		String debugLog=controller.getDebugLog();
		TLRPC.TL_phone_saveCallDebug req=new TLRPC.TL_phone_saveCallDebug();
		req.debug=new TLRPC.TL_dataJSON();
		req.debug.data=debugLog;
		req.peer=new TLRPC.TL_inputPhoneCall();
		req.peer.access_hash=call.access_hash;
		req.peer.id=call.id;
		ConnectionsManager.getInstance(currentAccount).sendRequest(req, new RequestDelegate(){
			@Override
			public void run(TLObject response, TLRPC.TL_error error){
                   if (BuildVars.LOGS_ENABLED) {
                       FileLog.d("Sent debug logs, response=" + response);
                   }
			}
		});
	}
}
 
Example 2
Source File: VoIPService.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void onControllerPreRelease(){
	if(needSendDebugLog){
		String debugLog=controller.getDebugLog();
		TLRPC.TL_phone_saveCallDebug req=new TLRPC.TL_phone_saveCallDebug();
		req.debug=new TLRPC.TL_dataJSON();
		req.debug.data=debugLog;
		req.peer=new TLRPC.TL_inputPhoneCall();
		req.peer.access_hash=call.access_hash;
		req.peer.id=call.id;
		ConnectionsManager.getInstance(currentAccount).sendRequest(req, new RequestDelegate(){
			@Override
			public void run(TLObject response, TLRPC.TL_error error){
                   if (BuildVars.LOGS_ENABLED) {
                       FileLog.d("Sent debug logs, response=" + response);
                   }
			}
		});
	}
}
 
Example 3
Source File: VoIPService.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void onTgVoipStop(TgVoip.FinalState finalState) {
	if (needRateCall || forceRating || finalState.isRatingSuggested) {
		startRatingActivity();
		needRateCall = false;
	}
	if (needSendDebugLog && finalState.debugLog != null) {
		TLRPC.TL_phone_saveCallDebug req = new TLRPC.TL_phone_saveCallDebug();
		req.debug = new TLRPC.TL_dataJSON();
		req.debug.data = finalState.debugLog;
		req.peer = new TLRPC.TL_inputPhoneCall();
		req.peer.access_hash = call.access_hash;
		req.peer.id = call.id;
		ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
			if (BuildVars.LOGS_ENABLED) {
				FileLog.d("Sent debug logs, response = " + response);
			}
		});
		needSendDebugLog = false;
	}
}
 
Example 4
Source File: VoIPService.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void onTgVoipStop(TgVoip.FinalState finalState) {
	if (needRateCall || forceRating || finalState.isRatingSuggested) {
		startRatingActivity();
		needRateCall = false;
	}
	if (needSendDebugLog && finalState.debugLog != null) {
		TLRPC.TL_phone_saveCallDebug req = new TLRPC.TL_phone_saveCallDebug();
		req.debug = new TLRPC.TL_dataJSON();
		req.debug.data = finalState.debugLog;
		req.peer = new TLRPC.TL_inputPhoneCall();
		req.peer.access_hash = call.access_hash;
		req.peer.id = call.id;
		ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
			if (BuildVars.LOGS_ENABLED) {
				FileLog.d("Sent debug logs, response = " + response);
			}
		});
		needSendDebugLog = false;
	}
}
 
Example 5
Source File: VoIPService.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
protected void callFailed(int errorCode) {
	if (call != null) {
		if (BuildVars.LOGS_ENABLED) {
			FileLog.d("Discarding failed call");
		}
		TLRPC.TL_phone_discardCall req = new TLRPC.TL_phone_discardCall();
		req.peer = new TLRPC.TL_inputPhoneCall();
		req.peer.access_hash = call.access_hash;
		req.peer.id = call.id;
		req.duration = controller != null && controllerStarted ? (int) (controller.getCallDuration() / 1000) : 0;
		req.connection_id = controller != null && controllerStarted ? controller.getPreferredRelayID() : 0;
		req.reason = new TLRPC.TL_phoneCallDiscardReasonDisconnect();
		ConnectionsManager.getInstance(currentAccount).sendRequest(req, new RequestDelegate() {
			@Override
			public void run(TLObject response, TLRPC.TL_error error) {
				if (error != null) {
                       if (BuildVars.LOGS_ENABLED) {
                           FileLog.e("error on phone.discardCall: " + error);
                       }
				} else {
                       if (BuildVars.LOGS_ENABLED) {
                           FileLog.d("phone.discardCall " + response);
                       }
				}
			}
		});
	}
	super.callFailed(errorCode);
}
 
Example 6
Source File: VoIPService.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
protected void callFailed(int errorCode) {
	if (call != null) {
		if (BuildVars.LOGS_ENABLED) {
			FileLog.d("Discarding failed call");
		}
		TLRPC.TL_phone_discardCall req = new TLRPC.TL_phone_discardCall();
		req.peer = new TLRPC.TL_inputPhoneCall();
		req.peer.access_hash = call.access_hash;
		req.peer.id = call.id;
		req.duration = controller != null && controllerStarted ? (int) (controller.getCallDuration() / 1000) : 0;
		req.connection_id = controller != null && controllerStarted ? controller.getPreferredRelayID() : 0;
		req.reason = new TLRPC.TL_phoneCallDiscardReasonDisconnect();
		ConnectionsManager.getInstance(currentAccount).sendRequest(req, new RequestDelegate() {
			@Override
			public void run(TLObject response, TLRPC.TL_error error) {
				if (error != null) {
                       if (BuildVars.LOGS_ENABLED) {
                           FileLog.e("error on phone.discardCall: " + error);
                       }
				} else {
                       if (BuildVars.LOGS_ENABLED) {
                           FileLog.d("phone.discardCall " + response);
                       }
				}
			}
		});
	}
	super.callFailed(errorCode);
}
 
Example 7
Source File: VoIPService.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private void acknowledgeCall(final boolean startRinging){
	if(call instanceof TLRPC.TL_phoneCallDiscarded){
           if (BuildVars.LOGS_ENABLED) {
               FileLog.w("Call " + call.id + " was discarded before the service started, stopping");
           }
		stopSelf();
		return;
	}
	TLRPC.TL_phone_receivedCall req = new TLRPC.TL_phone_receivedCall();
	req.peer = new TLRPC.TL_inputPhoneCall();
	req.peer.id = call.id;
	req.peer.access_hash = call.access_hash;
	ConnectionsManager.getInstance(currentAccount).sendRequest(req, new RequestDelegate() {
		@Override
		public void run(final TLObject response, final TLRPC.TL_error error) {
			AndroidUtilities.runOnUIThread(new Runnable(){
				@Override
				public void run(){
					if(sharedInstance==null)
						return;
                       if (BuildVars.LOGS_ENABLED) {
                           FileLog.w("receivedCall response = " + response);
                       }
					if (error != null){
                           if (BuildVars.LOGS_ENABLED) {
                               FileLog.e("error on receivedCall: " + error);
                           }
						stopSelf();
					}else{
						if(USE_CONNECTION_SERVICE){
							TelecomManager tm=(TelecomManager) getSystemService(TELECOM_SERVICE);
							Bundle extras=new Bundle();
							extras.putInt("call_type", 1);
							tm.addNewIncomingCall(addAccountToTelecomManager(), extras);
						}
						if(startRinging)
							startRinging();
					}
				}
			});
		}
	}, ConnectionsManager.RequestFlagFailOnServerErrors);
}
 
Example 8
Source File: VoIPService.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public void declineIncomingCall(int reason, final Runnable onDone) {
	stopRinging();
	callDiscardReason=reason;
	if(currentState==STATE_REQUESTING){
		if(delayedStartOutgoingCall!=null){
			AndroidUtilities.cancelRunOnUIThread(delayedStartOutgoingCall);
			callEnded();
		}else{
			dispatchStateChanged(STATE_HANGING_UP);
			endCallAfterRequest=true;
		}
		return;
	}
	if (currentState == STATE_HANGING_UP || currentState == STATE_ENDED)
		return;
	dispatchStateChanged(STATE_HANGING_UP);
	if (call == null) {
		if (onDone != null)
			onDone.run();
		callEnded();
		if (callReqId != 0) {
			ConnectionsManager.getInstance(currentAccount).cancelRequest(callReqId, false);
			callReqId = 0;
		}
		return;
	}
	TLRPC.TL_phone_discardCall req = new TLRPC.TL_phone_discardCall();
	req.peer = new TLRPC.TL_inputPhoneCall();
	req.peer.access_hash = call.access_hash;
	req.peer.id = call.id;
	req.duration = controller != null && controllerStarted ? (int) (controller.getCallDuration() / 1000) : 0;
	req.connection_id = controller != null && controllerStarted ? controller.getPreferredRelayID() : 0;
	switch (reason) {
		case DISCARD_REASON_DISCONNECT:
			req.reason = new TLRPC.TL_phoneCallDiscardReasonDisconnect();
			break;
		case DISCARD_REASON_MISSED:
			req.reason = new TLRPC.TL_phoneCallDiscardReasonMissed();
			break;
		case DISCARD_REASON_LINE_BUSY:
			req.reason = new TLRPC.TL_phoneCallDiscardReasonBusy();
			break;
		case DISCARD_REASON_HANGUP:
		default:
			req.reason = new TLRPC.TL_phoneCallDiscardReasonHangup();
			break;
	}
	final boolean wasNotConnected=ConnectionsManager.getInstance(currentAccount).getConnectionState()!=ConnectionsManager.ConnectionStateConnected;
	final Runnable stopper;
	if(wasNotConnected){
		if (onDone != null)
			onDone.run();
		callEnded();
		stopper=null;
	}else{
		stopper=new Runnable(){
			private boolean done=false;

			@Override
			public void run(){
				if(done)
					return;
				done=true;
				if(onDone!=null)
					onDone.run();
				callEnded();
			}
		};
		AndroidUtilities.runOnUIThread(stopper, (int) (VoIPServerConfig.getDouble("hangup_ui_timeout", 5)*1000));
	}
	ConnectionsManager.getInstance(currentAccount).sendRequest(req, new RequestDelegate() {
		@Override
		public void run(TLObject response, TLRPC.TL_error error) {
			if (error != null) {
                   if (BuildVars.LOGS_ENABLED) {
                       FileLog.e("error on phone.discardCall: " + error);
                   }
			} else {
				if (response instanceof TLRPC.TL_updates) {
					TLRPC.TL_updates updates = (TLRPC.TL_updates) response;
					MessagesController.getInstance(currentAccount).processUpdates(updates, false);
				}
                   if (BuildVars.LOGS_ENABLED) {
                       FileLog.d("phone.discardCall " + response);
                   }
			}
			if (!wasNotConnected){
				AndroidUtilities.cancelRunOnUIThread(stopper);
				if(onDone!=null)
					onDone.run();
			}
		}
	}, ConnectionsManager.RequestFlagFailOnServerErrors);
}
 
Example 9
Source File: VoIPService.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private void acknowledgeCall(final boolean startRinging){
	if(call instanceof TLRPC.TL_phoneCallDiscarded){
           if (BuildVars.LOGS_ENABLED) {
               FileLog.w("Call " + call.id + " was discarded before the service started, stopping");
           }
		stopSelf();
		return;
	}
	TLRPC.TL_phone_receivedCall req = new TLRPC.TL_phone_receivedCall();
	req.peer = new TLRPC.TL_inputPhoneCall();
	req.peer.id = call.id;
	req.peer.access_hash = call.access_hash;
	ConnectionsManager.getInstance(currentAccount).sendRequest(req, new RequestDelegate() {
		@Override
		public void run(final TLObject response, final TLRPC.TL_error error) {
			AndroidUtilities.runOnUIThread(new Runnable(){
				@Override
				public void run(){
					if(sharedInstance==null)
						return;
                       if (BuildVars.LOGS_ENABLED) {
                           FileLog.w("receivedCall response = " + response);
                       }
					if (error != null){
                           if (BuildVars.LOGS_ENABLED) {
                               FileLog.e("error on receivedCall: " + error);
                           }
						stopSelf();
					}else{
						if(USE_CONNECTION_SERVICE){
							TelecomManager tm=(TelecomManager) getSystemService(TELECOM_SERVICE);
							Bundle extras=new Bundle();
							extras.putInt("call_type", 1);
							tm.addNewIncomingCall(addAccountToTelecomManager(), extras);
						}
						if(startRinging)
							startRinging();
					}
				}
			});
		}
	}, ConnectionsManager.RequestFlagFailOnServerErrors);
}
 
Example 10
Source File: VoIPService.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public void declineIncomingCall(int reason, final Runnable onDone) {
	stopRinging();
	callDiscardReason=reason;
	if(currentState==STATE_REQUESTING){
		if(delayedStartOutgoingCall!=null){
			AndroidUtilities.cancelRunOnUIThread(delayedStartOutgoingCall);
			callEnded();
		}else{
			dispatchStateChanged(STATE_HANGING_UP);
			endCallAfterRequest=true;
		}
		return;
	}
	if (currentState == STATE_HANGING_UP || currentState == STATE_ENDED)
		return;
	dispatchStateChanged(STATE_HANGING_UP);
	if (call == null) {
		if (onDone != null)
			onDone.run();
		callEnded();
		if (callReqId != 0) {
			ConnectionsManager.getInstance(currentAccount).cancelRequest(callReqId, false);
			callReqId = 0;
		}
		return;
	}
	TLRPC.TL_phone_discardCall req = new TLRPC.TL_phone_discardCall();
	req.peer = new TLRPC.TL_inputPhoneCall();
	req.peer.access_hash = call.access_hash;
	req.peer.id = call.id;
	req.duration = controller != null && controllerStarted ? (int) (controller.getCallDuration() / 1000) : 0;
	req.connection_id = controller != null && controllerStarted ? controller.getPreferredRelayID() : 0;
	switch (reason) {
		case DISCARD_REASON_DISCONNECT:
			req.reason = new TLRPC.TL_phoneCallDiscardReasonDisconnect();
			break;
		case DISCARD_REASON_MISSED:
			req.reason = new TLRPC.TL_phoneCallDiscardReasonMissed();
			break;
		case DISCARD_REASON_LINE_BUSY:
			req.reason = new TLRPC.TL_phoneCallDiscardReasonBusy();
			break;
		case DISCARD_REASON_HANGUP:
		default:
			req.reason = new TLRPC.TL_phoneCallDiscardReasonHangup();
			break;
	}
	final boolean wasNotConnected=ConnectionsManager.getInstance(currentAccount).getConnectionState()!=ConnectionsManager.ConnectionStateConnected;
	final Runnable stopper;
	if(wasNotConnected){
		if (onDone != null)
			onDone.run();
		callEnded();
		stopper=null;
	}else{
		stopper=new Runnable(){
			private boolean done=false;

			@Override
			public void run(){
				if(done)
					return;
				done=true;
				if(onDone!=null)
					onDone.run();
				callEnded();
			}
		};
		AndroidUtilities.runOnUIThread(stopper, (int) (VoIPServerConfig.getDouble("hangup_ui_timeout", 5)*1000));
	}
	ConnectionsManager.getInstance(currentAccount).sendRequest(req, new RequestDelegate() {
		@Override
		public void run(TLObject response, TLRPC.TL_error error) {
			if (error != null) {
                   if (BuildVars.LOGS_ENABLED) {
                       FileLog.e("error on phone.discardCall: " + error);
                   }
			} else {
				if (response instanceof TLRPC.TL_updates) {
					TLRPC.TL_updates updates = (TLRPC.TL_updates) response;
					MessagesController.getInstance(currentAccount).processUpdates(updates, false);
				}
                   if (BuildVars.LOGS_ENABLED) {
                       FileLog.d("phone.discardCall " + response);
                   }
			}
			if (!wasNotConnected){
				AndroidUtilities.cancelRunOnUIThread(stopper);
				if(onDone!=null)
					onDone.run();
			}
		}
	}, ConnectionsManager.RequestFlagFailOnServerErrors);
}
 
Example 11
Source File: VoIPService.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private void acknowledgeCall(final boolean startRinging){
	if(call instanceof TLRPC.TL_phoneCallDiscarded){
           if (BuildVars.LOGS_ENABLED) {
               FileLog.w("Call " + call.id + " was discarded before the service started, stopping");
           }
		stopSelf();
		return;
	}
	if(Build.VERSION.SDK_INT>=19 && XiaomiUtilities.isMIUI() && !XiaomiUtilities.isCustomPermissionGranted(XiaomiUtilities.OP_SHOW_WHEN_LOCKED)){
		if(((KeyguardManager)getSystemService(KEYGUARD_SERVICE)).inKeyguardRestrictedInputMode()){
			if(BuildVars.LOGS_ENABLED)
				FileLog.e("MIUI: no permission to show when locked but the screen is locked. ¯\\_(ツ)_/¯");
			stopSelf();
			return;
		}
	}
	TLRPC.TL_phone_receivedCall req = new TLRPC.TL_phone_receivedCall();
	req.peer = new TLRPC.TL_inputPhoneCall();
	req.peer.id = call.id;
	req.peer.access_hash = call.access_hash;
	ConnectionsManager.getInstance(currentAccount).sendRequest(req, new RequestDelegate() {
		@Override
		public void run(final TLObject response, final TLRPC.TL_error error) {
			AndroidUtilities.runOnUIThread(new Runnable(){
				@Override
				public void run(){
					if(sharedInstance==null)
						return;
                       if (BuildVars.LOGS_ENABLED) {
                           FileLog.w("receivedCall response = " + response);
                       }
					if (error != null){
                           if (BuildVars.LOGS_ENABLED) {
                               FileLog.e("error on receivedCall: " + error);
                           }
						stopSelf();
					}else{
						if(USE_CONNECTION_SERVICE){
							ContactsController.getInstance(currentAccount).createOrUpdateConnectionServiceContact(user.id, user.first_name, user.last_name);
							TelecomManager tm=(TelecomManager) getSystemService(TELECOM_SERVICE);
							Bundle extras=new Bundle();
							extras.putInt("call_type", 1);
							tm.addNewIncomingCall(addAccountToTelecomManager(), extras);
						}
						if(startRinging)
							startRinging();
					}
				}
			});
		}
	}, ConnectionsManager.RequestFlagFailOnServerErrors);
}
 
Example 12
Source File: VoIPService.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private void acknowledgeCall(final boolean startRinging){
	if(call instanceof TLRPC.TL_phoneCallDiscarded){
           if (BuildVars.LOGS_ENABLED) {
               FileLog.w("Call " + call.id + " was discarded before the service started, stopping");
           }
		stopSelf();
		return;
	}
	if(Build.VERSION.SDK_INT>=19 && XiaomiUtilities.isMIUI() && !XiaomiUtilities.isCustomPermissionGranted(XiaomiUtilities.OP_SHOW_WHEN_LOCKED)){
		if(((KeyguardManager)getSystemService(KEYGUARD_SERVICE)).inKeyguardRestrictedInputMode()){
			if(BuildVars.LOGS_ENABLED)
				FileLog.e("MIUI: no permission to show when locked but the screen is locked. ¯\\_(ツ)_/¯");
			stopSelf();
			return;
		}
	}
	TLRPC.TL_phone_receivedCall req = new TLRPC.TL_phone_receivedCall();
	req.peer = new TLRPC.TL_inputPhoneCall();
	req.peer.id = call.id;
	req.peer.access_hash = call.access_hash;
	ConnectionsManager.getInstance(currentAccount).sendRequest(req, new RequestDelegate() {
		@Override
		public void run(final TLObject response, final TLRPC.TL_error error) {
			AndroidUtilities.runOnUIThread(new Runnable(){
				@Override
				public void run(){
					if(sharedInstance==null)
						return;
                       if (BuildVars.LOGS_ENABLED) {
                           FileLog.w("receivedCall response = " + response);
                       }
					if (error != null){
                           if (BuildVars.LOGS_ENABLED) {
                               FileLog.e("error on receivedCall: " + error);
                           }
						stopSelf();
					}else{
						if(USE_CONNECTION_SERVICE){
							ContactsController.getInstance(currentAccount).createOrUpdateConnectionServiceContact(user.id, user.first_name, user.last_name);
							TelecomManager tm=(TelecomManager) getSystemService(TELECOM_SERVICE);
							Bundle extras=new Bundle();
							extras.putInt("call_type", 1);
							tm.addNewIncomingCall(addAccountToTelecomManager(), extras);
						}
						if(startRinging)
							startRinging();
					}
				}
			});
		}
	}, ConnectionsManager.RequestFlagFailOnServerErrors);
}